gpt4 book ai didi

ruby-on-rails - Rails : HABTM - find all records with no association

转载 作者:行者123 更新时间:2023-12-03 17:33:22 25 4
gpt4 key购买 nike

我有2个模型(锻炼,设备),并且属于许多关系。如果使用Workout.find(:all, :joins => :equipment, :conditions => "equipment.id = 5"),则可以使用,但是如果使用Workout.find(:all, :joins => :equipment, :conditions => "equipment.id = null"),则不会返回没有关联的记录。有任何想法吗?

最佳答案

旋转一下;

Workout.joins("left join equipments e on workouts.id = e.workouts_id").where("e.id is null")

关于ruby-on-rails - Rails : HABTM - find all records with no association,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11279317/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com