Constantin,
You can''t. When you create a new Container object, it doesn''t
have an
associated object yet, is completely empty, but you have a Nil object
on your Container company_id attribute. (I''m guessing the relationship
is being named pickup_at). That''s what you are getting.
The AssociationProxy returns the target object methods only if it
exists.
I can''t think of a way to reflect on an inexistent referenced object.
Regards,
Jorge Corona.
On Sep 4, 8:23 pm, Constantin Gavrilescu <rails-mailing-l...@andreas-
s.net> wrote:> When the object referenced by the association exists, it''s a real
> AssociationProxy, and all the methods
work:http://apidock.com/rails/ActiveRecord/Associations/AssociationProxy
>
> >> Container.first.pickup_at.class.to_s
>
> => "Terminal"
>
> >> Container.first.pickup_at.aliased_table_name
>
> => "companies"
>
> When the object is new:
>
> >> Container.new.pickup_at.class
>
> => NilClass
>
> >> ImportContainer.new.pickup_at.aliased_table_name
>
> NoMethodError: You have a nil object when you didn''t expect it!
> The error occurred while evaluating nil.aliased_table_name
>
> It seems to be a real nil object, and not a AssociationProxy with the
> "class" method removed.
>
> The question is: How do I reflect on the association when the object is
> new?
> --
> Posted viahttp://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@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---