So this has been surprisingly difficult to locate a quick answer to. I’m using ActiveRecord in a pure console app, and I have my classes set up like so:
class Owner < ActiveRecord::Base
has_many :profiles
end
class Profile < ActiveRecord::Base
has_many :lines
belongs_to :owner
end
class Line < ActiveRecord::Base
belongs_to :profiles
end
Now normally i’d do something like..
Profile.create( :thing => "thing", :otherthing => "otherthing" )
How does AR know to link this instance of profile to an owner? What about a specific owner already in the database? How do I tell it? How would I do all of the links at once? (line, to profile, to owner)?
Read this to understand the basics. http://guides.rubyonrails.org/association_basics.html.