Group
has_many :topics, :as => :discussable (via a module)
Topic
belongs_to :discussable, :polymorphic => true
named_scope :unhidden, { :conditions => ['hidden = ?', false] }
Under rails 1.9.2 without the named_scope this works properly:
>> reload! ; Group.find(56).topics.size
Reloading...
...snip show tables etc...
Group Load (12.8ms) SELECT * FROM `groups` WHERE (`groups`.`id` = 56)
Topic Columns (13.6ms) SHOW FIELDS FROM `topics`
SQL (81.7ms) SELECT count(*) AS count_all FROM `topics` WHERE
(`topics`.discussable_id = 56 AND `topics`.discussable_type = 'Group')
However with the named scope in there:
>> reload! ; Group.find(56).topics.unhidden.size
Group Load (14.3ms) SELECT * FROM `groups` WHERE (`groups`.`id` = 56)
*Topic Load (40.1ms) SELECT * FROM `topics` WHERE
(`topics`.discussable_id = 56 AND `topics`.discussable_type = 'Group') *
Topic Columns (13.5ms) SHOW FIELDS FROM `topics`
SQL (11.8ms) SELECT count(*) AS count_all FROM `topics` WHERE (((hidden
= 0) AND (`topics`.discussable_id = 56 AND `topics`.discussable_type =
'Group')) AND (`topics`.discussable_id = 56 AND `topics`.discussable_type =
'Group'))
So the problem is under the seond one, it selects all the topics and then
does select count(*).
Under rails 1.9.1p243 this worked correctly in both cases.
Any ideas?
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.