As great as Rails 2.1 is, I for the life of me cannot figure out why
polymorphic associations do not support reconfiguring the type column
used.
For example, I have no way to do a polymorphic association using a
lookup hash which maps an integer to a class name.
Storing a TINYINT unsigned is waaaaay more efficient than storing a
string like "SomeActiveRecordModel" over and over again.
Looking in the association proxy classes for has_one and has_many, I
see:
def construct_sql
case
when @reflection.options[:as]
@finder_sql
"#{@reflection.quoted_table_name}.#{@reflection.options[:as]}_id
= #{@owner.quoted_id} AND " +
"#{@reflection.quoted_table_name}.#{@reflection.options[:as]}_type
= #{@owner.class.quote_value(@owner.class.base_class.name.to_s)}"
else
@finder_sql
"#{@reflection.quoted_table_name}.#{@reflection.primary_key_name}
#{@owner.quoted_id}"
end
@finder_sql << " AND (#{conditions})" if conditions
end
This cannot easily be changed. The type condition should be a function
call so we could easily modified. Has anybody thought about this?
--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---