假设我有这个:
class Tree < ActiveRecord::Base
has_many :fruits
has_many :flowers
end
class Fruit < ActiveRecord::Base
belongs_to :tree
end
class Flower < ActiveRecord::Base
belongs_to :tree
end
Run Code Online (Sandbox Code Playgroud)
如何进行有效的查询来获取Tree至少具有一个Flower或Fruit实例或两者的所有实例?这个想法不是得到那些根本Tree没有的东西。FlowerFruit