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.

enter image description here

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

enter image description here

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

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -