英文:
I need to fetch all the content which has content settings and which doesn't
问题
我需要获取所有具有内容设置和没有内容设置的内容,同时使用includes方法。内容设置表中有与content_id和编辑类型相关联的关联。
我之前使用左外连接做过这个操作,但我想使用includes方法执行这个查询。
英文:
I need to fetch all the content which has content settings and which doesn't, using both the includes methods. There is an association in the contentSetting table with the content_id and editor type.
I had done it with left outer join earlier but I have to do it with includes.
contents = Content.all
contents = contents
.left_outer_joins(:content_setting)
.where('content_settings.editor_type = ? OR content_settings.id IS NULL', '0')
but I want to perform this query using includes method.
答案1
得分: 1
我认为references
在这种情况下应该有所帮助:
Content
.includes(:content_setting)
.references(:content_settings)
.where('content_settings.editor_type = ? OR content_settings.id IS NULL', '0')
英文:
I think references
should help in this case:
Content
.includes(:content_setting)
.references(:content_settings)
.where('content_settings.editor_type = ? OR content_settings.id IS NULL', '0')
答案2
得分: 0
baseq = Content.includes(:content_setting)
baseq.where.missing(:bars).or(baseq.where(content_settings: { editor_type: 0 }))
英文:
baseq = Content.includes(:content_setting)
baseq.where.missing(:bars).or(baseq.where(content_settings: { editor_type: 0 }))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论