This project is archived and is in readonly mode.
Problem with find with :joins and :include in same call
-
Frederick Cheung
- Assigned user set to Frederick Cheung
-
mueller182 (at gmail)
Well, the same problem happens with a find using :include and :joins
-
James Le Cuirot
Ugh I'm behind on my project, the end finally looks near and then I run into this, with no workaround that I can see. :( Any ideas yet? I'm gonna start digging now.
-
James Le Cuirot
I've figured it out. It was caused by the fix for ticket #528 Check joins when determining preloading of includes. This fix tries to determine which tables you have explicitly joined so that you can force preloading (instead of regular eager loading) if you want to. The problem is that it does a bad job of this since it will also pick up tables named in the join condition. In my case and the case above, this table has to be explicitly named to prevent ambiguity. As far as I can see, it can only be resolved by replacing the somewhat nasty regex with an even nastier one.
/([.a-zA-Z_]+).?./
Becomes...
/\bJOIN\s+["
]?([\.a-zA-Z_]+)["]?\s/iThis could possibly be improved. Here's a patch against 2-3-stable anyway. I may add tests and a patch for master later. Really tired right now. :(
-
Frederick Cheung
Does someone familiar with several databases want to comment on whether joins always look like this (seems to me like they do but databases never cease to surprise me)? I seem to recall the some database uses [] to quote table names - i think the existing regexes just use . as a catchall
Other than that looks fine.
Separate from this, you should avoid all this if you use the form of joins where you name associations (since then rails doesn't have to parse a blob of sql to work out what is being joined
-
James Le Cuirot
I'm using PostgreSQL right now and I used MySQL before but those are the obvious cases. I checked the existing quote column/table methods and only found " and
. Most databases don't force you to quote anyway though, right?I know you can name the associations but in my case, I was actually joining a sub-select.
-
Frederick Cheung
They don't force you but you don't want it to break if you do choose to, which I believe why the other regexps just use . for the quoting character (if my memory of bugs past are correct)
-
James Le Cuirot
Sorry, the markup is confusing my comments slightly. I meant " and backticks.
What I should have said was that just . doesn't work for sub-selects before something like "LEFT OUTER JOIN (SELECT ..." will return SELECT as a table name. I considered [^(] but I think I dismissed it for some reason.
-
Rohit Arondekar
- State changed from new to stale
- Importance changed from to
Marking ticket as stale. If this is still an issue please leave a comment with suggested changes, creating a patch with tests, rebasing an existing patch or just confirming the issue on a latest release or master/branches.
-
Jeff Kreeftmeijer
Automatic cleanup of spam.
