Ruby on Rails - is many-to-many relation needed? -
im quite new ruby on rails, i've completed michael hart railstutorial.org , tutorial base of new project i'm working on simple electronic prescription service. feel confused many-to-many relations in ror , nice avoid them not sure if thats possible functionality need.
here basic eer relations table going connect prescription medicines should include.
i appreciate ideas how simplify one, or maybe it's not hard implement?
don't avoid many-to-many
association, it's working join model
you can use has_many :through
you'd need this:
#app/models/prescription.rb class prescription < activerecord::base has_many :relations has_many :medicines, through: :relations end #app/models/relation.rb class relation < activerecord::base belongs_to :prescription belongs_to :medicine end #app/models/medicine.rb class medicine < activerecord::base has_many :relations has_many :prescriptions, through: :relations end
Comments
Post a Comment