Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

231
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!