Rails4 and polymorphic handling #265

Closed
aaronchi opened this Issue Aug 7, 2013 · 7 comments

Comments

Projects
None yet
4 participants

aaronchi commented Aug 7, 2013

ActiveRecord 4 has some nice features for handling polymorphic associations that fail when squeel is added. For example, you can do this:

class Post
  belongs_to :item, :polymorphic => true
end

item = Item.first
post = Post.where(:item => item).first

This works in vanilla ActiveRecord but fails in squeel, apprently because it is treating the activerecord object as a symbol.

Peeja commented Aug 13, 2013

I'm hitting something similar, only in an even simpler case: it's not polymorphic. I believe if :item is not polymorphic in the above example, it will work in AR4 and not in Squeel.

AR4 seems to recognize :association_name => record in a where and turn it into :association_foreign_key => record.id (or, if it's polymorphic, :association_foreign_key => record.id, :association_foreign_type => record.class.name). Squeel appears to break that.

farnoy commented Aug 21, 2013

Can we hope for a fix?

Owner

ernie commented Aug 28, 2013

I'm just acknowledging that I've seen this issue, since I have gotten some e-mail about it.

Long story short, I was in Kenya a couple of weeks ago with no computer, and I'm strapped for time now that I've returned. If someone wants to put in a PR, I'm happy to look it over and merge if it checks out, but in the meantime, I'll just ask for your patience.

Thanks!

Owner

ernie commented Aug 28, 2013

Also, @Peeja, just to clarify, the behavior should be identical to AR where possible, so this is definitely not intentional. The reason we skip PredicateBuilder is because we lazily convert Squeel nodes, etc into their Arel counterparts at query time, instead of when creating the where.

ernie closed this in 2f5b485 Sep 3, 2013

farnoy commented Sep 3, 2013

Thanks for the solution. I'm unable to test it because I rewrote some parts to use pure AR instead of squeel, but glad to see a fix 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment