binarylogic / searchlogic

Searchlogic provides object based searching, common named scopes, and other useful tools.
http://rdoc.info/projects/binarylogic/searchlogic
MIT License
1.4k stars 133 forks source link

Invalid SQL is executed on rails 2.3.10 #131

Closed mataki closed 13 years ago

mataki commented 13 years ago

https://rails.lighthouseapp.com/projects/8994/tickets/4634-duplicate-association-conditions-are-generated-when-using-a-named_scope-on-an-association

On Rails 2.3.10, this ticket's commit is included. Invalid SQL is executed to work with searchlogic. http://gist.github.com/632095

We got critical trouble by this bug on production environment.

I don't have idea to resolve it. but, I recommend not to use Rails 2.3.10 with searchlogic until it is resolved.

mataki commented 13 years ago

I blogged about this bug. but it is only japanese, sorry. http://bit.ly/9y0isf

gravis commented 13 years ago

Also having a critical issue here with 2.3.10 : http://gist.github.com/640183 A whole table is loaded into rails, and the server stops responding, being out of memory :(

ledermann commented 13 years ago

Same problem here after upgrading Rails to 2.3.10. The generated SQL is different for two consecutive calls of the same query. After some investigations on the console I found this pattern:

Contact.find(42).addresses.my_scope.descend_by_created_at.all
# => wrong (does not respect my_scope)
Contact.find(42).addresses.my_scope.descend_by_created_at.all
# => ok
# [now make a simple change in address.rb and save it]
reload!
Contact.find(42).addresses.my_scope.descend_by_created_at.all
# => wrong
Contact.find(42).addresses.my_scope.descend_by_created_at.all
# => ok

It seems that the query is WRONG after the association class was loaded the first time (e.g. in development env, after editing the class). The second time Searchlogic generates the correct SQL.

Hope this helps.

ghost commented 13 years ago

This was fixed in a related issue. Upgrade to the latest version for a fix. The association scopes were being dropped, thus loading in unscoped records. I made a small change that hands back that responsibility back to ActiveRecord, this way the issue won't happen again.

mataki commented 13 years ago

Great! Thank you to fix it!

ghost commented 13 years ago

No problem, sorry for the delay, haven't been around lately.