[question] Can I have a User model as "just a String"?
olleolleolle opened this issue · comments
Hi!
I'm using current_user
with a username as a string. That string comes from another database system. I can't edit that value, and I don't need to.
I don't have a Sequel Model around that, in the app database.
Naturally, this does not work.
Error message: undefined method `pk' for "OLLE":String
Stack trace:
gems/jruby/2.3.0/gems/sequel-4.45.0/lib/sequel/model/associations.rb:2569:in `set_associated_object'
gems/jruby/2.3.0/gems/sequel-4.45.0/lib/sequel/model/associations.rb:2097:in `block in modifier='
gems/jruby/2.3.0/gems/sequel_audited-0.2.2/lib/sequel/plugins/audited.rb:17:in `before_validation'
gems/jruby/2.3.0/gems/sequel-4.45.0/lib/sequel/model/base.rb:2278:in `block in _valid?'
gems/jruby/2.3.0/gems/sequel-4.45.0/lib/sequel/model/base.rb:1328:in `around_validation'
gems/jruby/2.3.0/gems/sequel-4.45.0/lib/sequel/model/base.rb:2276:in `_valid?'
gems/jruby/2.3.0/gems/sequel-4.45.0/lib/sequel/model/base.rb:1764:in `block in save'
gems/jruby/2.3.0/gems/sequel-4.45.0/lib/sequel/model/base.rb:2298:in `checked_save_failure'
gems/jruby/2.3.0/gems/sequel-4.45.0/lib/sequel/model/base.rb:1764:in `save'
gems/jruby/2.3.0/gems/sequel-4.45.0/lib/sequel/model/base.rb:1782:in `save_changes'
gems/jruby/2.3.0/gems/sequel-4.45.0/lib/sequel/model/base.rb:2474:in `update_restricted'
gems/jruby/2.3.0/gems/sequel-4.45.0/lib/sequel/model/base.rb:1910:in `update'
gems/jruby/2.3.0/gems/sequel_polymorphic-0.3.1/lib/sequel_polymorphic/sequel_polymorphic.rb:83:in `block in _add_version'
gems/jruby/2.3.0/gems/sequel-4.45.0/lib/sequel/model/associations.rb:2335:in `add_associated_object'
gems/jruby/2.3.0/gems/sequel-4.45.0/lib/sequel/model/associations.rb:1921:in `block in add_version'
gems/jruby/2.3.0/gems/sequel_audited-0.2.2/lib/sequel/plugins/audited.rb:269:in `add_audited'
gems/jruby/2.3.0/gems/sequel_audited-0.2.2/lib/sequel/plugins/audited.rb:280:in `after_create'
Can I work around the "mutating User is a model" assumption?
Our workaround was: just add a User model in the app database as well.
Hi @olleolleolle,
Modifier/audited_by needs to be a model as sequel_polymorphic is used in order to match these.
You can have a Admin model and a User model both being a modifier.
There probably won't be any change to that.
But if you want to change that, you have to change:
https://github.com/jnylen/sequel_audited/blob/master/lib/sequel/plugins/audited.rb#L12