I am new to Rails so bear with me…
I am trying to create a set of data related to 2 different models. I currently have the following models:
class M < ActiveRecord::Base
belongs_to :u
belongs_to :s
end
class U < ActiveRecord::Base
has_many :m
has_many :s, :through => m:
end
class S < ActiveRecord::Base
has_many :m
has_many :u, :through => m;
end
In the system, the user can create many Us and Ss. But when creating an M it should make sure that there exist a reference to an "u" and an "s".
I know i can do the following:
m1 = M.create()
u1.ms << m1
s1.ms << m1
Which has all the appropriate reference, is there a better way?