如何使用 ruby DataMapper 生成带有连接语句的查询?
IE。
class Model1
property id, Serial
has n :Model2s, :parent_key => [ :id ], :child_key => [ :model1_id ]
end
class Model2
property :id, Serial
property :model1_id, Integer
has n :Model3s, :parent_key => [ :id ], :child_key => [ :model2_id ]
end
class Model3
property :id, Serial
property :model2_id, Integer
end
现在我希望 DataMapper 创建一个查询,如:
SELECT ... FROM model1 INNER JOIN model2 ON model1.id = model2.model1_id INNER JOIN model3 ON model2.id = model3.model2_id;
目前它在访问它们时延迟加载所有关系与单个查询,这非常慢。