DataMapper连接语句

时间:2012-05-04 12:04:29

标签: ruby join datamapper

如何使用ruby DataMapper生成带有连接语句的查询?

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;

目前,在访问时,它会使用单个查询延迟加载所有关系,这非常慢。

0 个答案:

没有答案