{"action":"closed","issue":{"url":"https://api.github.com/repos/salsify/goldiloader/issues/60","repository_url":"https://api.github.com/repos/salsify/goldiloader","labels_url":"https://api.github.com/repos/salsify/goldiloader/issues/60/labels{/name}","comments_url":"https://api.github.com/repos/salsify/goldiloader/issues/60/comments","events_url":"https://api.github.com/repos/salsify/goldiloader/issues/60/events","html_url":"https://github.com/salsify/goldiloader/issues/60","id":296172340,"number":60,"title":"Too many assiated models may be loaded","user":{"login":"jgrau","id":108088,"avatar_url":"https://avatars0.githubusercontent.com/u/108088?v=4","gravatar_id":"","url":"https://api.github.com/users/jgrau","html_url":"https://github.com/jgrau","followers_url":"https://api.github.com/users/jgrau/followers","following_url":"https://api.github.com/users/jgrau/following{/other_user}","gists_url":"https://api.github.com/users/jgrau/gists{/gist_id}","starred_url":"https://api.github.com/users/jgrau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jgrau/subscriptions","organizations_url":"https://api.github.com/users/jgrau/orgs","repos_url":"https://api.github.com/users/jgrau/repos","events_url":"https://api.github.com/users/jgrau/events{/privacy}","received_events_url":"https://api.github.com/users/jgrau/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-02-11T08:32:28Z","updated_at":"2018-02-13T13:17:00Z","closed_at":"2018-02-13T13:17:00Z","author_association":"NONE","body":"First of all thanks for a great gem. I use this heavily.\r\n\r\nI'll try to explain my problem:\r\n\r\nI have a controller action that does something like this\r\n\r\n```\r\ndef related\r\n  room = Room.find(params[:id])\r\n  collection = SimilarRooms.call(room: room, limit: 50)\r\n  # collection is now an array of 50 Rooms\r\n  render json: collection\r\nend\r\n```\r\n\r\nThe SimilarRooms service (stripped down to what matters):\r\n\r\n```\r\ndef call\r\n  similar_rooms = Room.within(100, origin: room) # <- this is the problematic line I think\r\n  # finds all the rooms within 100km of the origin room\r\n  # this returns a lot of rooms\r\n  # ... do some math and some custom ordering ...\r\n  similar_rooms.take(limit) # take the first 50 rooms\r\nend\r\n```\r\n\r\nWhen I render the collection (which only includes the top 50 rooms) I also include data from an associated `company` `has_one` relation. That association is preloaded, however, it looks like it includes the company for every room found in the `within` query and not just the companies for the 50 rooms in the array that I try to render.\r\n\r\nDoes this explanation make sense? Is there anything to be done about this?"}}
{"actor":{"display_login":"jgrau"}}