I am trying to use self
in an association condition. I can't simply use self
though because then it will access the actual class instead of the instance (like in this issue). So I have a class with an association that looks like this:
# in l.rb
has_many :curent_ts, {
source: :t,
through: :t_l_relationships,
conditions: proc { " #{self} " }
}
Obviously that is not the condition I want, but this is the condition I am using to debug so that I can see the value of self. The thing is, I have another that has almost exactly the same association:
# in e.rb
has_many :current_ls, {
source: :l,
through: :t_l_relationships,
conditions: proc { " #{self} " }
}
The self
in e.rb always evaluates to an instance of e. The self
in l.rb evaluates instead to something like: #<ActiveRecord::Associations::JoinDependency::JoinAssociation:0x00000011f24fe8>
. It is an association instead of an instance of l. Why is this happening?
To make things worse, self
in l evaluates to an instance of l, but ONLY on older accounts in my project. When I create a new account, the main page crashes because self
evaluates to an Association.
Does anyone know what may be causing this? Or another way to access the instance of the class (like self in the methods) in the association condition?
I am using Rails 3.2.11.
Aucun commentaire:
Enregistrer un commentaire