You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a problem with originator method. It does not respect inheritance the way it should. Let me explain.
If we have the following model:
class Person < ActiveRecord::Base
has_paper_trail
end
and
class Employee < Person
end
When you create an Employee the column item_type on Versions table takes the value Person, which is correct according to Rails polymorphic associations (it has to contain the base class name). For the same good practice, the reify method respects the inheritance and polymorphic mechanism correct: It expects the item_type to contain the base class.
On the other hand, the originator method, which has the following code:
def originator
version_class.with_item_keys(self.class.name, id).last.try :whodunnit
end
when called on Employee instance will try to fetch the entries of Versions table which have value Employee, and none will be found. This is due to the self.class.name part of the originator method implementation. I believe it should have been self.class.base_class.name instead, but you are the person to decide whether my suggestion is correct or not.
Hi @airblade ,
I have a problem with
originator
method. It does not respect inheritance the way it should. Let me explain.If we have the following model:
and
When you create an
Employee
the columnitem_type
onVersions
table takes the valuePerson
, which is correct according to Rails polymorphic associations (it has to contain the base class name). For the same good practice, thereify
method respects the inheritance and polymorphic mechanism correct: It expects theitem_type
to contain the base class.On the other hand, the
originator
method, which has the following code:when called on
Employee
instance will try to fetch the entries ofVersions
table which have valueEmployee
, and none will be found. This is due to theself.class.name
part of theoriginator
method implementation. I believe it should have beenself.class.base_class.name
instead, but you are the person to decide whether my suggestion is correct or not.@pmatsinopoulos
The text was updated successfully, but these errors were encountered: