This project is archived and is in readonly mode.
AR belongs_to :include option doesn't do anything
-
David Trasbo
I was able to duplicate this with version 2.3.5 of Rails:
➜ code rails -v Rails 2.3.5 ➜ code rails named_scope_include_option ... ➜ code cd named_scope_include_option ➜ named_scope_include_option script/generate model foo bar_id:integer ... ➜ named_scope_include_option script/generate model bar ... ➜ named_scope_include_option rake db:migrate (in /Users/dtrasbo/code/named_scope_include_option) ... ➜ named_scope_include_option script/console Loading development environment (Rails 2.3.5) ruby-1.8.7-p249 > Foo.baz.each do |foo| ruby-1.8.7-p249 > foo.bar ruby-1.8.7-p249 ?> end => [#<Foo id: 1, bar_id: 1, created_at: "2010-04-14 19:31:29", updated_at: "2010-04-14 19:31:29">]Sure enough, the log shows two entries:
SELECT * FROM "foos" SELECT * FROM "bars" WHERE ("bars"."id" = 1) -
David Trasbo
Here's the
Foomodel, by the way.Barhas no code in it.class Foo < ActiveRecord::Base belongs_to :bar named_scope :baz, :include => :bar end -
Santiago Pastorino
- State changed from new to open
- Tag changed from 2.3.4, activerecord to 234, activerecord
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.
-
Santiago Pastorino
- State changed from open to stale
-
Julian Mehnle
- Tag changed from 234, activerecord to 2.3.11, 2311, 234, activerecord
This is still broken in 2.3.11. Didn't have a chance to test it with ActiveRecord/Rails 3 yet.
-
Dave Schweisguth
In Rails 3.0.6
-
when querying multiple objects, eager-loaded belongs_to are loaded in a single separate query with 'where id in (...)', which makes sense since left joining could bring in the same date more than once. I'd have sworn this was the Rails 2.3.11 behavior but I no longer have a Rails 2.3.11 app handy to check.
-
there is still a bug in that when querying a single object with find, ActiveRecord should know that it can left join, but it still takes a second query to get the belonged-to object.
-