Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

237
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda