0
私のモデルは入札、オークション、および会社です。私のBid
Auction
への関連が壊れているようです。何らかの理由Auction.joins(:bids).where(bids: @bids).to_sql
のために私が混乱している何を私に壊れた関連付けのレール4
"SELECT "auctions".*
FROM "auctions"
INNER JOIN "bids" ON "bids"."auction_id" = "auctions"."id"
WHERE "auctions"."auction_id" IN
(SELECT "bids"."id" FROM "bids" INNER JOIN "inventory_parts" ON
"bids"."inventory_part_id" = "inventory_parts"."id"
WHERE "inventory_parts"."company_id" = 1)"
を与えているクエリが条件WHERE "auctions"."auction_id"
を持っている理由です。それは簡潔にするためにWHERE "auctions"."id"
する必要があり、私は私は私の問題で果たすべき役割を持っていると信じていモデルと私は思うの関連付けをリストアップするつもりだ問題
私はオークションモデル
を持っていますclass Auction < ActiveRecord::Base
belongs_to :company
has_one :auction_part, dependent: :destroy
has_one :part, through: :auction_part
has_many :bids, dependent: :destroy
入札モデル
class Bid < ActiveRecord::Base
has_one :company, through: :inventory_part
belongs_to :auction
belongs_to :inventory_part
と当社モデル
class Company < ActiveRecord::Base
has_secure_password
has_many :auctions, dependent: :destroy
has_many :bids, through: :inventory_parts
has_many :inventory_parts, dependent: :destroy
したがって、 'Auction.joins(:bids).where(bids:@bids)'は間違っていますか?団体ではない? – gemart
はい、 'where(column:value)'を渡すたびに、railsは現在のモデルテーブルの列を見つけます。だから、あなたのケースでは、 'オークション' –
そして '入札:@入札'これは奇妙なクエリの考えられる理由です –