This project is archived and is in readonly mode.
Using :joins when calling first on an association ignores joins
-
Neeraj Singh
- State changed from new to open
- Milestone set to 3.x
- Importance changed from to Low
The author says that this is an issue in 2.3-stable . I can reproduce it in rails edge too.
-
Neeraj Singh
- Assigned user set to Aaron Patterson
- Tag changed from 2-3-stable, 2.3.10, activerecord, associations, first to 2-3-stable, 2.3.10, activerecord, associations, first, rails3
-
Neeraj Singh
I spent some time (infact some good time) looking at it.
The path followed by
parrot.pirates.all(:joins => :ship)is
association_collection -> method_missing
and then call
Pirate.with_scope(@scope) do
args # {:joins => :capital} endstraight forward and simple. However notice that it does select pirates.*
In the case of
parrot.pirates.first(:joins => :ship, :order => "catchphrase")it hits
association_collection => first
association_collection => findthere method construct_find_options is called which takes the options as input. However it does not use the input and clobbers the options[:joins] and
{:joins => :ship } is lost forever.The fix of that is something like this https://gist.github.com/703946 .That takes care of building the joins. However the sql produced is
select * from piratesAny attempt to have
select pirates.* fromis making other test fail which rely on getting the join attribute . Remember we are dealing with habtm.
-
omarqureshi
Sorry, have come back to this after a long hiatus.
Isn't this what is required? The problem is the joins, not the select clause and infact, is probably preferable to have instead of table. since it is a join and a :select has not been specified.
-
rails
- Tag changed from 2-3-stable, 2.3.10, activerecord, associations, first, rails3 to 2-3-stable, 2310, activerecord, associations, first, rails3
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
rails
- State changed from open to stale