RoR:搜索逻辑:如何进行左连接,而不是默认的左内连接?

发布于 2024-11-28 09:58:36 字数 142 浏览 3 评论 0原文

我正在根据引用另一个表的字段进行排序(并根据另一个表的“名称”字段进行排序)。问题是,当我的第一组对象中有一些条目没有对另一个条目的引用时,该条目将被排除在排序之外。

简而言之,我有一个列是对另一个表的引用(并对该表中的列进行排序),但我也想包含空引用。

I'm doing sorting based on a field that references another table (and sorting on that other table's 'name' field). The issue is that when my first set of objects has some entries that don't have a reference to the other, that entry is excluded from the sorting.

So.. in short, I have a column that is a reference to another table (and sorting over a column in that table), but I also want to include null references.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叹沉浮 2024-12-05 09:58:36

我不是 100% 确定我理解你的问题,但是例如,当你编写一个named_scope时,你可以传递这样的选项:

named_scope descend_it_by_that_other_column, 
:select => "",
:joins => "LEFT JOIN ...", 
:conditions => "..."

另一个例子:

def my_fancy_method_returning_things
 association_name.all :limit => 5, :joins => 'LEFT JOIN ... ON ... = ...', :order => ...'
end

I am not 100% sure I understand your question, but for example, when you write a named_scope you can pass options like this:

named_scope descend_it_by_that_other_column, 
:select => "",
:joins => "LEFT JOIN ...", 
:conditions => "..."

another example:

def my_fancy_method_returning_things
 association_name.all :limit => 5, :joins => 'LEFT JOIN ... ON ... = ...', :order => ...'
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文