Imagine the following situation:
I have a dog model and a house model. A dog can belong to a house, and there can be many dogs in a house, therefore:
Class Dog < ActiveRecord::Base belongs_to :house end Class House < ActiveRecord::Base has_many :dogs end
Now imagine that I also want to create dogs that do not have a home. They do not belong to the house. Can I use this relationship structure and just not tell :house_id when I create it?
Is there a better practice?
Arr .: I used this analogy to simplify my problem, but my real situation is this: I have a model that the user can generate instances of. He can also create collections of these instances, but he can leave the instance outside the collection.
ruby ruby-on-rails activerecord
JoΓ£o Daniel May 05 '12 at 2:14 pm 2012-05-05 14:14
source share