Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 列出与当前activerecord对象不相关的数据_Ruby On Rails_Activerecord - Fatal编程技术网

Ruby on rails 列出与当前activerecord对象不相关的数据

Ruby on rails 列出与当前activerecord对象不相关的数据,ruby-on-rails,activerecord,Ruby On Rails,Activerecord,你可以把它写在一行里 group = Group.find(id) // lets say group 1 // find tests that are not added to this group 首先找到属于特定组的测试ID,然后使用或也可以使用@Vasilisa查询使用连接 Test.left_outer_joins(:groups).where.not(groups: {id: id}) 一班轮 group_test_ids = group.tests.ids #test ids

你可以把它写在一行里

group = Group.find(id) // lets say group 1
// find tests that are not added to this group 

首先找到属于特定组的测试ID,然后使用或也可以使用@Vasilisa查询使用连接

Test.left_outer_joins(:groups).where.not(groups: {id: id})
一班轮

group_test_ids = group.tests.ids #test ids which belongs to group

tests = Test.where.not(id: group_test_ids) # tests which not contain that group

试试这个
group\u test\u ids=group.tests.ids
tests=test.where.not(id:group\u test\u ids)
@ts good one:)。我想我不应该给表命名
group
。它与内置的活动记录冲突method@ts我把它修好后,让我试试你的解决办法,但我肯定会的
group_test_ids = group.tests.ids #test ids which belongs to group

tests = Test.where.not(id: group_test_ids) # tests which not contain that group
tests = Test.where.not(id: group.tests.ids)