我不得不通過模式有一個基本的has_many其中一個客戶可以有多種遊戲:使用相關值,以主動管理篩選表(軌道4 /主動聯繫)
客戶模型屬於合作伙伴並且因此具有partner_id列,對於屬於合作伙伴的遊戲模型也是如此。
models/customer.rb
has_many :customer_games
has_many :games, through: :customer_games
belongs_to :partner, :foreign_key => 'partner_id'
models/game.rb
has_many :customer_games
has_many :customers, through: :customer_games
belongs_to :partner, :foreign_key => 'partner_id'
models/customer_games.rb
belongs_to :customer, :foreign_key => 'customer_id'
belongs_to :game, :foreign_key => 'game_id'
在管理/ customer.rb,我有(工作)表給我細節全部特定客戶的遊戲。我得到這樣說:
panel "Games and infos of these games for this customer:" do
table_for customer.customer_games do |t|
t.column("Name") { |customer_game| link_to customer_game.game.title, admin_game_path(customer_game.game), target: :blank }
t.column("Partner") { |customer_game| if customer_game.game.partner.name.present?
link_to customer_game.game.partner.name, admin_partner_path(customer_game.game.partner), target: :blank
else
status_tag('Empty')
end
}
t.column("Country") { |customer_game| customer_game.game.country }
end
end
我的問題:我想只在上表中顯示遊戲中的合作伙伴屬於等於給客戶的合作伙伴。
也就是說,如果您在customer_games表中使用了games_id和customer_id,並且如果我檢查與game_id鏈接的partner_id以及與customer_id相關聯的partner_id,如果它們相等,則此遊戲可以出現在我的表格中。
很難用言語解釋,對不起。
僅供參考,我的最後一次嘗試我試過,但它不工作:
panel "Games and infos of these games for this customer:" do
table_for customer.customer_games.where(game_id.game.partner_id == customer_id.customer.partner_id) do |t|
t.column("Game Name") { |customer_game| link_to customer_game.game.title, admin_game_path(customer_game.game), target: :blank }
t.column("Partner") { |customer_game| if customer_game.game.partner.name.present?
link_to customer_game.game.partner.name, admin_partner_path(customer_game.game.partner), target: :blank
else
status_tag('Empty')
end
}
t.column("Country") { |customer_game| customer_game.game.country }
end
end
至少我沒有得到一個錯誤現在,但我得到所有我認爲的遊戲,而不僅僅是那些customer_game.game.partner_id == customer_game.customer.partner_id – Mathieu