Wednesday, February 3, 2010

[Rails] Re: has_many with 3 models

BTW, the partners are of class User. So from users to partners, it's
many-to-many.
From users to relationship_types, or from relationship_types to links,
it's one-to-many.
From links to partners, it's one-to-one.

Thanks.

On Feb 3, 6:20 pm, Vincent P <ease...@gmail.com> wrote:
> Hi,
>
> I have the following 3 models.  User , Relationship_type, and Link.
>
>      User
> has_many :relationship_types
>
>      Relationship_type
> belongs_to :users
> has_many :links
>
>       Link
> belongs_to :relationship_type
>
> The Link model has a column :partner.  I'd like to find all partners
> of a user so I'd like to say in User model
>
> has_many :partners
>                 :through  => :relationship_type, :link
>
> but that creates errors.  How can I do this to be able to say
> something like userA.partners  .
>
> Similarly, how can I do the reverse, getting all users that link to a
> partner , e.g. partnerA.users?
>
> In addition, how can I get to User from Link, to say something like
> linkA.user  ?
>
> Thanks.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate