Hi there,
is there somebody who could help me out with the correct query syntax?
The situation is the following:
MODELS:
Hi there,
is there somebody who could help me out with the correct query syntax?
The situation is the following:
MODELS:
Hi there,
is there somebody who could help me out with the correct query syntax?
The situation is the following:
MODELS:
user has_many :memberships
user has_many :groups,
:through => :memberships,
:source => :groupTABLES:
users:
- idmemberships:
- id
- user_id
- group_id
- accepted (true/false)groups:
- id=> What I need is the collection of groups ("@groups") for a user, but
only if the "memberships" have "true" in the column "accepted".I started with something like this (but don't know how to fix the
conditions part):@groups = @user.groups.find(:all, :conditions => { "the memberships must
have 'true' in the 'accepted' column" })
Craig White wrote:
memberships:
I started with something like this (but don't know how to fix the
conditions part):@groups = @user.groups.find(:all, :conditions => { "the memberships must
have 'true' in the 'accepted' column" })----
@user = User.find($SomeIdNumber)
@groups = Group.find(:all, :conditions => ["accepted IS TRUE AND user_id
= ?", @user])Craig
Hey Craig,
thanks for your answer! One question back though:
In your 'conditions' statement: doesn't "accepted" refer to the 'group'
table? I'm asking because the tricky part in my case is: "accepted"
refers to/exists only in the 'membership' table... (see above: the model
is: user has_many :groups, :through => :memberships, :source => :group)
Tom
You can use the :conditions option:
has_many :accepted_groups, :through => :memberships, :source
=> :group,
:conditions => ['memberships.accepted =?', true]