Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

238
Visualizações
Model relations for Workers/Jobs/Orders all working in sync

I am attempting to have customers place an Order and when they place an Order it will have a status: uncompleted in the Order database entry.

A Worker can claim one of those Orders and begin a Job. When the Worker has taken the Order and made it a Job I am attempting to make the Order status status: inprogress and the Job status status: inprogress and then when the Worker completed the Job the Order status should be status: completed and the Job status status: completed.

I am wondering if I have set up my Model relations the correct way to be able to alter the status of Order and Job when a Worker creates a Job within a PostgreSQL database.

My models are set up like so:

worker.rb

devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable

has_many :jobs

order.rb

belongs_to :job

job.rb

 belongs_to :worker
 has_one :worker
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can achieve such functionality by using sql triggers or ActiveRecord callbacks. Particularly after_update callback. The idea is when you update a record data some code executes.

Or you can use state machine gems for managing your statuses. AASM gem for example has build in callbacks which are executed when status changes.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda