{"comment":{"created_at":"2011-10-15T14:10:24Z","body":"Work fine only with :category. has n, :categories still performs N+1:\r\n\r\n    Manufacturer.all.map do |m|\r\n      [m.id, m.category.code, m.categories.map {|o| o.code }]\r\n    end\r\n\r\nThis is as expected:\r\n\r\n    DEBUG - (0.004123) SELECT \"id\",  \"created_at\", \"updated_at\", \"category_id\" FROM \"manufacturers\" WHERE (\"deleted_at\" IS NULL AND \"id\" > 29430) ORDER BY \"id\"\r\n    DEBUG - (0.002080) SELECT \"id\", \"code\" FROM \"categories\" WHERE \"id\" IN (1195, 957, 1038, 1, 706, 680) ORDER BY \"id\"\r\n\r\nThis is not as expected:\r\n\r\n    DEBUG - (0.001774) SELECT \"categories\".\"id\", \"categories\".\"code\" FROM \"categories\" INNER JOIN \"manufacturer_categories\" ON \"categories\".\"id\" = \"manufacturer_categories\".\"category_id\" INNER JOIN \"manufacturers\" ON \"manufacturer_categories\".\"manufacturer_id\" = \"manufacturers\".\"id\" WHERE \"manufacturer_categories\".\"manufacturer_id\" = 29431 GROUP BY \"categories\".\"id\", \"categories\".\"code\" ORDER BY \"categories\".\"id\"\r\n    DEBUG - (0.001802) SELECT \"categories\".\"id\", \"categories\".\"code\" FROM \"categories\" INNER JOIN \"manufacturer_categories\" ON \"categories\".\"id\" = \"manufacturer_categories\".\"category_id\" INNER JOIN \"manufacturers\" ON \"manufacturer_categories\".\"manufacturer_id\" = \"manufacturers\".\"id\" WHERE \"manufacturer_categories\".\"manufacturer_id\" = 29432 GROUP BY \"categories\".\"id\", \"categories\".\"code\" ORDER BY \"categories\".\"id\"\r\n    ...\r\n\r\n\r\n","updated_at":"2011-10-15T14:10:24Z","url":"https://api.github.com/repos/datamapper/dm-core/issues/comments/2415599","id":2415599,"user":{"gravatar_id":"43084203a14bc25c8bb2c1fe9495f2ac","avatar_url":"https://secure.gravatar.com/avatar/43084203a14bc25c8bb2c1fe9495f2ac?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","url":"https://api.github.com/users/pirj","id":6916,"login":"pirj"}},"action":"created","issue":{"number":155,"created_at":"2011-10-15T13:08:04Z","pull_request":{"diff_url":null,"patch_url":null,"html_url":null},"body":"Assuming a model:\r\n\r\n    class Manufacturer\r\n      include DataMapper::Resource\r\n    \r\n      property :id, Serial\r\n      \r\n      belongs_to :category\r\n    ...\r\n    end\r\n    \r\n    class Category\r\n      include DataMapper::Resource\r\n    \r\n      property :id, Serial\r\n      property :code, String\r\n    end\r\n\r\nLet's run a query which should perform one request:\r\n\r\n    Manufacturer.all.map do |m|\r\n      {\r\n        :id => m.id,\r\n        :category => m.category.nil? ? nil : m.category.code,\r\n      }\r\n    end\r\n\r\nresults in multiple fetching of Category:\r\n\r\n    SELECT \"categories\".\"id\", \"categories\".\"code\" FROM \"categories\" INNER JOIN \"manufacturer_categories\" ON \"categories\".\"id\" = \"manufacturer_categories\".\"category_id\" INNER JOIN \"manufacturers\" ON \"manufacturer_categories\".\"manufacturer_id\" = \"manufacturers\".\"id\" WHERE \"manufacturer_categories\".\"manufacturer_id\" = 29481 GROUP BY \"categories\".\"id\", \"categories\".\"code\" ORDER BY \"categories\".\"id\"\r\n","comments":5,"title":"Strategic Eager Loading issue (N+1)","updated_at":"2011-10-15T14:10:24Z","url":"https://api.github.com/repos/datamapper/dm-core/issues/155","id":1917438,"assignee":null,"milestone":null,"closed_at":null,"user":{"gravatar_id":"43084203a14bc25c8bb2c1fe9495f2ac","avatar_url":"https://secure.gravatar.com/avatar/43084203a14bc25c8bb2c1fe9495f2ac?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","url":"https://api.github.com/users/pirj","id":6916,"login":"pirj"},"html_url":"https://github.com/datamapper/dm-core/issues/155","labels":[],"state":"open"},"legacy":{"issue_id":1917438,"comment_id":2415599}}