I love the query interface (ActiveMethod::QueryMethods), but one thing
has bugged me: why doesn't it generate calls for polymorphic
associations? For example:

class MyModel < ActiveRecord::Base
belongs_to :parent, :polymorphic => true
end

I would expect:

MyModel.where(:parent => a)

to be equivalent to:

MyModel.where("my_models.parent_id = ? AND my_models.parent_type = ?",
a.id, a.class.base_class.name)

Is there a philosophical reason it doesn't make this transformation?

- ff

P.S.: After writing this, I realize it's not just for polymorphism. I
would expect the NON-polymorphic case to transform:

MyModel.where(:parent => a)

into

MyModel.where("my_models.parent_id = ?", a.id)

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Tim Shaffer at Mar 28, 2012 at 1:13 pm
    When you write "belongs_to :parent" Rails expects there to be a class
    called Parent.

    If you want this to be related to the MyModel class, you'll need to
    explicitly state that:

    belongs_to :parent, :class_name => 'MyModel'

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/i62MUc2cQI4J.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedMar 22, '12 at 7:02p
activeMar 28, '12 at 1:13p
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Fearless Fool: 1 post Tim Shaffer: 1 post

People

Translate

site design / logo © 2021 Grokbase