Please send this to the rails group:
http://groups.google.com/group/rubyonrails-talk


On Thu, Apr 11, 2013 at 12:32 AM, John Chow <[email protected]> wrote:

> So I was trying to resolve an issue in my application where I couldn't do
> proper validation when creating associated models. After doing a Google
> search, I finally found the solution: :inverted_of.
>
> So it seems to me this is a totally awesome option, one that has both
> performance as well as logical benefits. I'm probably not seeing the
> drawbacks, but it seems to me that it should be used as much as possible.
> Does anybody have perspective why this isn't enabled by default (or at
> least talked about more in the Rails community)?
>
> Sample Code:
>
> class Car < ActiveRecord::Base
>   has_many :tires
> end
>
> class Tire < ActiveRecord::Base
>   belongs_to :car
>   validates :car, presence: true
> end
>
> c = Car.new
> c.tires.build #now I have a Tire object ready to save...
> c.save! # this will explode, saying that car doesn't exist for the tire!
> Although this will work with the :inverse_of option:
>
> class Car < ActiveRecord::Base
>   has_many :tires, inverse_of :car
> end
>
> --
> You received this message because you are subscribed to the Google Groups
> "rspec" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msg/rspec/-/Mn9KatDxNvIJ.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to