I''m working on a cost estimation tool, that allows each estimate created to override base assumptions of price, cost, etc. Everything was fine, until we said, "Let''s add a ''target net revenue'' property." So, the resource model got a "target" column. The override model got a "new_target" column. But, whenever I set resource.target, I don''t get a resource at the end; I get target. In other words: old_resource = resource.clone resource.target = new_target resource == old_resource # false resource == new_target # true -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060417/332a516d/attachment.html
Josh on Rails wrote:> I''m working on a cost estimation tool, that allows each estimate created > to override base assumptions of price, cost, etc. > > Everything was fine, until we said, "Let''s add a ''target net revenue'' property." > > So, the resource model got a "target" column. The override model got a > "new_target" column. > > But, whenever I set resource.target, I don''t get a resource at the end; > I get target. In other words: > > old_resource = resource.clone > resource.target = new_target > resource == old_resource # false > resource == new_target # true"target" is a method on AssociationProxy, which is the parent of the class that implements the "resource" association attribute on your model. resource.target is the associated object itself, not its resource attribute! I spent part of the weekend delving into that code, and I think the proxy methods should all have names that start with "proxy_" to avoid those sorts of collisions. Or at least be documented! -- Josh Susser http://blog.hasmanythrough.com -- Posted via http://www.ruby-forum.com/.
I opened a ticket for this issue: http://dev.rubyonrails.org/ticket/4769 -- Josh Susser http://blog.hasmanythrough.com -- Posted via http://www.ruby-forum.com/.
I feel your pain. I just posted about this after hitting the same issue at work today. I must have spent a few hours trying to figure out what was wrong with our model, because in our case ''target'' was an association itself, which meant that the consequences of using it were much stealthier and weirder: http://www.rubyfu.com/2007/06/transparent-proxies-part-2.html --Brendan Josh on Rails wrote:> I''m working on a cost estimation tool, that allows each estimate created > to > override base assumptions of price, cost, etc. > > Everything was fine, until we said, "Let''s add a ''target net revenue'' > property." > > So, the resource model got a "target" column. The override model got a > "new_target" column. > > But, whenever I set resource.target, I don''t get a resource at the end; > I > get target. In other words: > > old_resource = resource.clone > resource.target = new_target > resource == old_resource # false > resource == new_target # true-- 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 -~----------~----~----~----~------~----~------~--~---
target is not a reserved word. It is however used in ActiveRecord for their associations. That might be where you are running into problems. /Shawn On 6/19/07, Brendan Baldwin <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > I feel your pain. I just posted about this after hitting the same issue > at work today. I must have spent a few hours trying to figure out what > was wrong with our model, because in our case ''target'' was an > association itself, which meant that the consequences of using it were > much stealthier and weirder: > > http://www.rubyfu.com/2007/06/transparent-proxies-part-2.html > > --Brendan > > Josh on Rails wrote: > > I''m working on a cost estimation tool, that allows each estimate created > > to > > override base assumptions of price, cost, etc. > > > > Everything was fine, until we said, "Let''s add a ''target net revenue'' > > property." > > > > So, the resource model got a "target" column. The override model got a > > "new_target" column. > > > > But, whenever I set resource.target, I don''t get a resource at the end; > > I > > get target. In other words: > > > > old_resource = resource.clone > > resource.target = new_target > > resource == old_resource # false > > resource == new_target # true > > > -- > 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 -~----------~----~----~----~------~----~------~--~---