在我的应用程序中,我有以下模型
费用.rb
class Fee < ActiveRecord::Base
acts_as_paranoid
belongs_to :instructor_student
belongs_to :instructor
has_many :fee_payment_notifications, dependent: :destroy
end
class FeePaymentNotification < ActiveRecord::Base
belongs_to :fee
end
讲师.rb
class Instructor < ActiveRecord::Base
has_many :fees
has_many :fee_payment_notifications, through: :fees
end
我想用付费通知做内部加入费
当我直接使用费用连接和费用支付通知时,它会给我以下错误
@instructor.fee_payment_notifications.joins(:fee)
PG::UndefinedTable: ERROR: invalid reference to FROM-clause entry for table "fees"
LINE 1: ..."."id" = "fee_payment_notifications"."fee_id" AND "fees"."de...
^
HINT: Perhaps you meant to reference the table alias "fees_fee_payment_notifications".
: SELECT "fee_payment_notifications".* FROM "fee_payment_notifications" INNER JOIN "fees" "fees_fee_payment_notifications" ON "fees_fee_payment_notifications"."id" = "fee_payment_notifications"."fee_id" AND "fees"."deleted_at" IS NULL INNER JOIN "fees" ON "fee_payment_notifications"."fee_id" = "fees"."id" WHERE "fees"."deleted_at" IS NULL AND "fees"."instructor_id" = $1
可能是因为字段被删除了,所以我想用下面的查询进行手动连接
@instructor.fee_payment_notifications.select("fee_payment_notifications.* from fee_payment_notifications AS fp INNER JOIN fees as f ON fp.fee_id = f.id")
它给了我以下的错误
第1行:…ns AS fp INNER JOIN fees AS f ON fp.fee_id=f.id FROM“费”。。。
:选择“费用支付通知”。*从“费用支付通知”中选择“费用支付通知”作为fp内部加入费,从“费用支付通知”中选择“费用支付通知”的“内部加入费”,从“费用支付通知”中选择“费用”。“费用id”=“费用”。“id”,其中“费用”。“删除at”为空,“费用”。“讲师id”=1美元
=>#
如何编写手动加入费用和费用支付通知的查询?