state_machines-activerecord
state_machines-activerecord copied to clipboard
Map attribute aliases to column names when initializing
Fixes https://github.com/state-machines/state_machines-activemodel/issues/2
@seuros @rafaelfranca there seem to be some job errors (not test failures) - can you re-run the jobs?
@joelvh can you rebase/merge master to this branch ?
@joelvh I think alias_attribute should be in active-model
cc @rafaelfranca
@seuros do you have a suggestion of how to accomplish this in ActiveModel? Using Pry, I didn't see any calls from the constructor handling the attributes using ActiveModel, from what I recall because I also thought it might fit there. The place to implement this in AR was much clearer.
@seuros I've come up with a fix for ActiveModel in https://github.com/state-machines/state_machines-activemodel/pull/28. However, my tests to see if ActiveRecord is fixed by this indicate the params handled by ActiveModel don't get passed to ActiveRecord.
I'm doing some investigating, but it would appear my previous comment still stands, that AR either doesn't use the AM initialization or the transformed params are not passed along properly.
@seuros my latest investigation points to define_state_initializer
defined in ActiveRecord and ActiveModel implementations, but they don't inherit from each other. Is that a correct observation? That would explain what I saw using pry and why the AR implementation is not fixed by this PR alone.
It would seem that we need separate fixes (e.g. the two PRs I've created) unless there's a way to to have AR's initializer trigger AM's inside the state machine.
@seuros I've rebased this
@seuros just checking to see if this is the route to go or the ActiveModel PR.
@seuros will this be merged?