I have a rails app that contains workorders. I’m going to be loading workorders from another system. That system uses a single table for parent and child workorders.
I added a field to the workorders table called parent_id
Is this the right coding in the Workorder model?
class ParentWorkorder
belongs_to :parent, class_name => "Workorder"
belongs_to :child, class_name => "Workorder", :foreign_key => "parent_id"
end
Or would you advise against doing this – and instead create a child workorder table? I think that might make it harder to integrate with the other system.
Any guidance would be greatly appreciated!
You can do this in a single table with Rails as well, and for that matter with a single model. I don’t see why you’d need to complicate your app with an additional
ParentWorkordermodel like you have done. I would instead do the following:I’m pretty sure this will give you the functionality that you want.