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
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.