0
考慮我有軌道模型名爲A,B,C,D與以下關係。如何定義has_many通過通過軌道關聯通過
A has_many B
B belongs_to C
A has_many C via B
C belongs_to D
現在,應該如何定義下面的關聯方式?
A has_many D via C
考慮我有軌道模型名爲A,B,C,D與以下關係。如何定義has_many通過通過軌道關聯通過
A has_many B
B belongs_to C
A has_many C via B
C belongs_to D
現在,應該如何定義下面的關聯方式?
A has_many D via C
A has_many Bs
A has_many Cs, :through => Bs
(i.e B has_many Cs)
C belongs_to :D
A has_many Ds :through => Bs
SELECT COUNT(*) FROM `Ds` INNER JOIN `Cs` ON `Ds`.`id` = `Cs`.`D_id` INNER JOIN `Bs` ON `Cs`.`B_id` = `Bs`.`id` WHERE `Bs`.`A_i
你有測試此代碼..不工作我最終 –
更新的問題..'B屬於C' –