Paul Rosania
2010-May-27 00:16 UTC
[PATCH] Rails 3: fields_for helper doesn''t work with association proxy objects
Request for eyeballs. :-) Mongoid uses association proxy objects. It overrides #nil? => false when the association is missing. However since it uses proxy objects, !!assocation is always true. I have created a ticket with a patch that changes the association nil test to call assocation.nil? rather than use implicit coercion of the variable. See: https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4711-patch-rails-3-fields_for-helper-doesnt-work-with-association-proxy-objects -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Michael Koziarski
2010-May-29 01:38 UTC
Re: [PATCH] Rails 3: fields_for helper doesn''t work with association proxy objects
> Mongoid uses association proxy objects. It overrides #nil? => false > when the association is missing. However since it uses proxy > objects, !!assocation is always true.This is why active record doesn''t use proxy objects for nil belongs_to and has_one associations, you can''t override the boolean value of your objects.> > I have created a ticket with a patch that changes the association nil > test to call assocation.nil? rather than use implicit coercion of the > variable.These proxy objects don''t follow correct ruby semantics and I''m not entirely sure that we should take the performance hit to work around that bug. There are bound to be other places where we use this form and we''re not going to fix all of them. -- Cheers Koz -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Paul Rosania
2010-May-29 05:33 UTC
Re: [PATCH] Rails 3: fields_for helper doesn''t work with association proxy objects
Understood. I will flip this back to the Mongoid team. So to clarify, as a matter of implementation, ORMs seeking compatibility with Rails should never use proxy objects for belongs_to or has_one associations? On Fri, May 28, 2010 at 9:38 PM, Michael Koziarski <michael@koziarski.com>wrote:> > Mongoid uses association proxy objects. It overrides #nil? => false > > when the association is missing. However since it uses proxy > > objects, !!assocation is always true. > > This is why active record doesn''t use proxy objects for nil belongs_to > and has_one associations, you can''t override the boolean value of your > objects. > > > > > I have created a ticket with a patch that changes the association nil > > test to call assocation.nil? rather than use implicit coercion of the > > variable. > > These proxy objects don''t follow correct ruby semantics and I''m not > entirely sure that we should take the performance hit to work around > that bug. There are bound to be other places where we use this form > and we''re not going to fix all of them. > > -- > Cheers > > Koz > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-core+unsubscribe@googlegroups.com<rubyonrails-core%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Michael Koziarski
2010-May-29 05:45 UTC
Re: [PATCH] Rails 3: fields_for helper doesn''t work with association proxy objects
> So to clarify, as a matter of implementation, ORMs seeking compatibility > with Rails should never use proxy objects for belongs_to or has_one > associations?It''s not really a rails thing, it''s people expecting their library to use by ruby developers expecting idiomatic ruby code to work. if some_object.something my_thingy = some_object.something || SOME_DEFAULT These two cases are pretty fundamental, and while the null object pattern is nice and clean, the fact that they can never work right should be a sign it''s not a great idea to try it. -- Cheers Koz -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Paul Rosania
2010-May-29 16:23 UTC
Re: [PATCH] Rails 3: fields_for helper doesn''t work with association proxy objects
Makes sense, thanks. On Sat, May 29, 2010 at 1:45 AM, Michael Koziarski <michael@koziarski.com>wrote:> > So to clarify, as a matter of implementation, ORMs seeking compatibility > > with Rails should never use proxy objects for belongs_to or has_one > > associations? > > It''s not really a rails thing, it''s people expecting their library to > use by ruby developers expecting idiomatic ruby code to work. > > if some_object.something > > my_thingy = some_object.something || SOME_DEFAULT > > These two cases are pretty fundamental, and while the null object > pattern is nice and clean, the fact that they can never work right > should be a sign it''s not a great idea to try it. > > -- > Cheers > > Koz > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-core+unsubscribe@googlegroups.com<rubyonrails-core%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Maybe Matching Threads
- Setting the value of a primary key field
- [PATCH] Add :touch option to has_many associations
- Filter Ordering in Edge Rails (Rev 7143)
- Polymorphic URL helpers documentation and fixes
- Updating a belongs_to foreign key leaves the old association object available