-
Notifications
You must be signed in to change notification settings - Fork 213
broken hash conditions when querying for an activerecord object on a joined table #338
base: master
Are you sure you want to change the base?
Conversation
Looks like a dup of #313 which was closed, but this behavior definitely fails. |
@dontfidget Thank you very much. Does it mean AR can pass this test? Squeel has a long history when AR was not as good as current. So it provided another way to build predicates to Arel. From Rails 3.0 to 4.2, AR changed a lot and is changing a lot, so it's harder to keep the same behaviors with AR. I'd like to consider your suggestion to use AR's code as possible as we can. It needs lots of works. Any information you provide would be helpful :) |
I assume AR can pass the test. It was in my app and it started failing when I added squeel. Unfortunately, I don't know any more about AR than taking a cursory glance and seeing that there was something called a predicate builder. I don't know how hard it would to use it. In general, I don't understand why squeel is involved at all for a where clause that isn't passed a block, but I guess it must because it is built on top of arel rather than AR. Anyhow, I just worked the problem by writing it as: Comment.joins(:article).where('articles.person_id' => person}) Incidentally, the reason this syntax is handy is that you can pass both a relation and a single AR record to it, which I've found convenient when defining scopes. |
hum... you can also use squeel like this: Comment.joins { article }.where { article.person_id == person } It's also convenient when defining scopes :) |
That true, but I'm not in the habit of using squeel unless I really need it Andrew On Wed, Sep 10, 2014 at 10:14 PM, Xiang Li [email protected] wrote:
|
Yes, one of Squeel's goal is to make users couldn't detect the existence of Squeel when they are not using them. If you find more compatible problems, just tell me, I would schedule them one by one. Then I would try to find a way to refactor the code. Thank you. |
@bigxiang, hi, do you plan to move it forward? |
Not really a pull request, just a test. Seems like squeel breaks the following expressions:
These will both raise an exception telling us that 'articles' cannot be converted to a class.
The fix looks like it would be pretty involved. Essentially squeel is trying to replicate AR predicate builder, but it might be better offer using it, and somehow converting the resulting arel back into something it can work with because trying to keep the behavior up to date and matching might be a pain.