Pete Wright wrote:> Ok, I''m having a brain fart, so forgive me if this is a dumb
question.
>
> A user owns a house. Simple relationship there. Now, a user owns
> possessions. Nothing too taxing there. Now, a user can own more than
> one house and could own more than one ipod, but the user can only use
> the ipod in the house they are currently in. Trickier!
>
> Is there a built in ActiveRecord way of representing this (only
> getting a possessions list in the currently selected house for the
> current user) rather than the manual approach I''m about to take of
> adding a method to the House class that I pass a user id into?
>
> --------------------------------------------------
> Peter Wright
> froogle@tinfoilcat.net <mailto:froogle@tinfoilcat.net>
>
> Personal Blog -> http://peterwright.blogspot.com
> Agile Development Blog -> http://exceeding-expectations.blogspot.com
>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
Thinking about the relationships (rather than representing in AR), I
think there is a difference between owning a house (which is also a
container, as may be an office, or storage place, also the user may own
more than one house), and movable objects (possessions). I would think
the relationship between these containers (ugly name!) and possessions
is one of location, i.e. a container has_one location, a possession
has_one location, a location belongs_to a possession and belongs_to a
location, and a container has_many possessions through location.
Of course you could model the container-possession relationship as a
has_and_belongs_to_many, but I suspect you will want to add attributes
to the relationship, such as when it began (i.e. when it was moved
there), and when it ended.
HTH