Reputation: 7810
Is there any conflict to set a User
model to be versioned with paper_trail
? I have a model 'User' as follows:
class User < ActiveRecord::Base
has_paper_trail
end
The problem is that whenever I call user#versions
I get an exception:
ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'versions.user_id' in 'where clause': SELECT `versions`.* FROM `versions` WHERE (`versions`.user_id = 6)
(exception thrown when called versions
on a User
with id = 6
.
I also have problem when I am trying to save a User
. I get the following exception:
ActiveRecord::StatementInvalid: Mysql2::Error: Column 'item_id' cannot be null: INSERT INTO `versions` (`event`, `created_at`, `item_id`, `item_type`, `object`, `whodunnit`) VALUES ('update', '2011-11-17 10:38:43', NULL, NULL, '--- ....
which seems that save
does not populate the item_id
and item_type
.
Any help would be much appreciated.
Thanks in advance
Upvotes: 1
Views: 797
Reputation: 7810
The problem was that I had also added has_many :versions
in my User
model and there was a conflict.
To avoid the conflict, I followed what the paper_trail
mentions in the documentation:
has_paper_trail :versions => :paper_trail_versions
Upvotes: 1