hee guys…
I have a problem with HABTM…
I have articles en users… wich are connected to rights… beceause
users can have more then 1 right and rights can have more than one
user… and the same by articles of course
I have 3 models:
the user: has_and_belongs_to_many :rights
the article: has_and_belongs_to_many :rights
and rights: has_and_belongs_to_many :users
has_and_belongs_to_many :articles
and 2 join tables.
I have a user_id and I want to list all the articles which he has access
to:
@user = User.find_by_id(2)
@right = @user.rights
@article_list= @right.articles
but this doesn’t work… Does anyone now how to get multiple articles
from one user ?
Hello,
You are actually getting a array of rights from this:
@right = @user.rights
So not a right per se. You should call @right.articles on a Right
object…
Julien.
On Nov 4, 4:00 pm, Heldop S. [email protected]
[email protected] wrote:
Hello,
You are actually getting a array of rights from this:
@right = @user.rights
So not a right per se. You should call @right.articles on a Right
object…
Julien.
On Nov 4, 4:00 pm, Heldop S. [email protected]
Thanxs for the response Julien !!
Hmmm I think I dont understand it quit well …
is tryed a few things…
@right = User.find_by_id(1)
@article_list= @right.articles
and tryed:
@right = User.find_by_id(1)
@article = @right.articles
@article_list= @articles.articles
and:
@right = User.find_by_id(1)
@article_list = @right.articles.rights
but it all doens’t work 
I hope someone can tell wat I do wrong…
Heldop S. wrote:
[email protected] wrote:
Hello,
You are actually getting a array of rights from this:
@right = @user.rights
So not a right per se. You should call @right.articles on a Right
object…
Julien.
On Nov 4, 4:00 pm, Heldop S. [email protected]
Thanxs for the response Julien !!
Hmmm I think I dont understand it quit well …
is tryed a few things…
@right = User.find_by_id(1)
@article_list= @right.articles
and tryed:
@right = User.find_by_id(1)
@article = @right.articles
@article_list= @articles.articles
and:
@right = User.find_by_id(1)
@article_list = @right.articles.rights
but it all doens’t work 
I hope someone can tell wat I do wrong…
a little update…
If i say that right_id is 1 than it does work…
@right = Right.find(1)
@article_list = @right.articles
but if I do:
@right = Right.find(:all)
@article_list = @right.articles
so I want to select all the right ID’s and have there the articles from
it is comming with an error: undefined method `articles’
I hope someone can help me