Query Help

HEllo all,

Kindly look into the below query

@access_senders = GroupUser.find_by_sql “select distinct user_id from
group_users where group_id in (SELECT group_id FROM group_users where
user_id=2)”

when i inspect the @access_senders i get the below

[#<GroupUser user_id: 2>, #<GroupUser user_id: 41>, #<GroupUser user_id:
3518>,
#<GroupUser user_id: 3519>, #<GroupUser user_id: 3520>, #<GroupUser
user_id: 352
1>, #<GroupUser user_id: 3522>, #<GroupUser user_id: 3523>]

now i want to append 3 into the above result set…#<GroupUser user_id:
3>

is it poosible to do …
pls help me up

You could union it in the sql or do this in ruby:

@access_senders << GroupUser.new(:user_id => 3)

Cheers
Luke

On 20 March 2010 09:57, Newb N. [email protected] wrote:

[#<GroupUser user_id: 2>, #<GroupUser user_id: 41>, #<GroupUser user_id:
3518>,
#<GroupUser user_id: 3519>, #<GroupUser user_id: 3520>, #<GroupUser
user_id: 352
1>, #<GroupUser user_id: 3522>, #<GroupUser user_id: 3523>]

now i want to append 3 into the above result set…#<GroupUser user_id:
3>

Can you provide the model relationships (has_many and so on) and what
you are trying to achieve in words rather than sql?

Colin