On Jan 16, 12:59 pm, Wes Gamble <[email protected]>
wrote:
> How can I remove an association from an AR model with a monkey patch?
>
> Assume:
>
> class Foo < AR::Base
> has_many :bars
> end
>
> It's a long story, but in one particular data loading (not running the
> app. context), I'd like to remove the has_many association to :bars.
>
> Can I do that?
It sounds like you want to make sure that code that does this:
@foo.bars
would raise a NoMethodFound exception? If so, you can just reopen the
class:
class Foo
def bars
raise NoMethodError.new("undefined method 'bars'")
end
end
Then,
@foo.bars # => raises exception
However, this isn't really removing all of remnants of the
association, so again it depends on what constitutes "removed enough"
for your situation.
Jeff
purpleworkshops.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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---