0
我想從我的店選擇最新的4個交易的這部分引用,與has_and_belongs_to_many關係,並即時得到這個錯誤:沒有爲表「商店」的條目,但它不能從查詢
There is an entry for table "stores", but it cannot be referenced from this part of the query
class Deal < ActiveRecord::Base
has_and_belongs_to_many :stores
end
class Store < ActiveRecord::Base
has_and_belongs_to_many :deals
end
我的查詢
SELECT * FROM (SELECT stores.id AS store_id, deals.*,
dense_rank() OVER (
PARTITION BY deals.stores.id
ORDER BY deals.created_at DESC
) AS deal_rank
FROM "deals"
INNER JOIN "listings"
ON "listings"."deal_id" = "deals"."id"
INNER JOIN "images"
ON "images"."id" = "deals"."image_id"
INNER JOIN "deals_stores"
ON "deals_stores"."deal_id" = "deals"."id"
INNER JOIN "stores"
ON "stores"."id" = "deals_stores"."store_id"
ORDER BY deals.created_at desc)
AS ranked_deals
WHERE (deal_rank <= 4)
你也可以發表您的表定義?這部分是否正確:deals.stores.id –