V
V
Viktor Vsk2014-08-25 16:15:17
ruby
Viktor Vsk, 2014-08-25 16:15:17

rails. How to remove (undefine) associations\relations?

Suppose we declare an association in a class:

class User < Activerecord::Base
has_many :posts
end

How can I remove this association further in runtime? For example, through:
User.class_eval do
...
end

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Platonov, 2014-08-25
@kirillplatonov

has_many is converted to a set of methods. You can try removing them, but there are quite a few of them. And in general, this is a dirty patching, it is better not to do this.
Explain the context of the task. Perhaps your problem can be solved in a much simpler way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question