Hi I have a following query in my code.
GroupUser.find_by_sql ["select user_id from group_users where group_id
=?",6] and is return me
[#<GroupUser:0x835c5d4 @attributes={"user_id"=>"1"}>,
#<GroupUser:0x835c5ac @attributes={"user_id"=>"6"}>] this
how it possible in rails so code return me [1,6] not above array?
also it possible to find intersection between to array of objects?
Hi I have a following query in my code.
GroupUser.find_by_sql ["select user_id from group_users where group_id
=?",6] and is return me
[#<GroupUser:0x835c5d4 @attributes={"user_id"=>"1"}>,
#<GroupUser:0x835c5ac @attributes={"user_id"=>"6"}>] this
how it possible in rails so code return me [1,6] not above array?
also it possible to find intersection between to array of objects?
Please reply immediate.
You should be able to do something like
array = GroupUser.find_by_sql(blah blah blah).collect {|group_user|
user_id } to get just an array back (or something close to that)
To intersect arrays, the brute force method would be to iterate the
first array, checking if the element in question is in the second array,
if not, remove it. The net result is a list of items in both arrays.
Hi I have a following query in my code.
GroupUser.find_by_sql ["select user_id from group_users where
group_id
=?",6] and is return me
[#<GroupUser:0x835c5d4 @attributes={"user_id"=>"1"}>,
#<GroupUser:0x835c5ac @attributes={"user_id"=>"6"}>] this
how it possible in rails so code return me [1,6] not above array?
also it possible to find intersection between to array of objects?
Please reply immediate.
You should be able to do something like
array = GroupUser.find_by_sql(blah blah blah).collect {|group_user|
user_id } to get just an array back (or something close to that)
To intersect arrays, the brute force method would be to iterate the
first array, checking if the element in question is in the second
array,
if not, remove it. The net result is a list of items in both arrays.
Hi I have a following query in my code.
GroupUser.find_by_sql ["select user_id from group_users where group_id
=?",6] and is return me
[#<GroupUser:0x835c5d4 @attributes={"user_id"=>"1"}>,
#<GroupUser:0x835c5ac @attributes={"user_id"=>"6"}>] this
how it possible in rails so code return me [1,6] not above array?
sql = "select user_id from group_users where group_id = 6"
GroupUser.connection.select_values(sql)