It all began when a collegue said that "our free text search throws if the
user enters something with a dot".  A bit of investigation showed that
ActiveRecord produced a different set of queries depending on the user input
containing a dot or not.  The :include is handled with a single query with a
join, or with two separate queries.

This is not a big problem in most cases; it only has a performance impact.
In our case there was a failure because the :include joins a table which
another scope joins for a different reason.  We would never have noticed
this otherwise.

I dug a bit, and found that the reason is that method
ActiveRecord::Base.tables_in_string treats anything before a dot like a
table name.  So a condition like

  ["x = ?", params[:input]]

can produce a query "x = 'foo.bar'", and tables_in_string reports that we
reference a table named "foo".

It's not a big problem for our application; the simple workaround for me was
to filter out dots in user input.  But I think it's not good that AR can
behave differently according to user input.  So I filed a ticket and
prepared a patch.

https://rails.lighthouseapp.com/projects/8994/tickets/3446-tables_in_string-matches-literal-string-containing-dot#ticket-3446-2

Cheers,

Matteo

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" 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-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to