Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.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 3 Rails3:查找具有关系但通过特定值排除某些关系的记录_Ruby On Rails 3_Activerecord - Fatal编程技术网

Ruby on rails 3 Rails3:查找具有关系但通过特定值排除某些关系的记录

Ruby on rails 3 Rails3:查找具有关系但通过特定值排除某些关系的记录,ruby-on-rails-3,activerecord,Ruby On Rails 3,Activerecord,Hi有两种型号(Rails3) 阿姨 朋友 在哪里 阿姨:你有很多朋友吗 及 朋友:属于姑妈 现在,我想得到所有与朋友X无关的阿姨 我试过这样的方法: 包括(:friends).where('friends.id!=?',X) 但它不起作用 附言:我还需要包括那些没有任何朋友的阿姨们 这是以下各项的输出: @results = Aunt.custom(true).select('aunts.id, aunts.goal').joins("LEFT OUTER JOIN friends r ON

Hi有两种型号(Rails3)

阿姨 朋友

在哪里

阿姨:你有很多朋友吗

朋友:属于姑妈

现在,我想得到所有与朋友X无关的阿姨

我试过这样的方法:

包括(:friends).where('friends.id!=?',X)

但它不起作用

附言:我还需要包括那些没有任何朋友的阿姨们

这是以下各项的输出:

@results = Aunt.custom(true).select('aunts.id, aunts.goal').joins("LEFT OUTER JOIN friends r ON aunts.id = r.aunt_id").where('r.other_value != ? or r.id is NULL', 4259 ).ordered_by_status_creation.select('aunts.id, aunts.goal')
aunts
LEFT OUTER JOIN friends r ON中选择aunts.id、aunts.goal aunts.id=r.aunt\u id,其中
aunts
deleted\u at
为空且
在('MyType')和(is_custom=1)和(r.另一个_值)中引导
类型
!=4259或r.id为空)按状态说明订购,aunts.id说明


有什么想法吗?

我想你需要这样的东西:

Aunt.joins("LEFT OUTER JOIN friends ON aunts.id = friends.friend_id").where('friends.id != ? or friends.id is NULL', X ).select

您可以按如下方式使用范围


范围:没有房子,lambda{{124; param{124; param?{:conditions=>[“related|id!=?”,param.id]}:{}

阿姨加入(:childrens)。在哪里('childrens.id?',X)给你?返回所有的阿姨@rainkinz