state_machines-activerecord icon indicating copy to clipboard operation
state_machines-activerecord copied to clipboard

Map attribute aliases to column names when initializing

Open joelvh opened this issue 3 years ago • 9 comments

Fixes https://github.com/state-machines/state_machines-activemodel/issues/2

joelvh avatar Apr 16 '21 23:04 joelvh

@seuros @rafaelfranca there seem to be some job errors (not test failures) - can you re-run the jobs?

joelvh avatar Apr 17 '21 00:04 joelvh

@joelvh can you rebase/merge master to this branch ?

seuros avatar Apr 17 '21 06:04 seuros

@joelvh I think alias_attribute should be in active-model

cc @rafaelfranca

seuros avatar Apr 17 '21 17:04 seuros

@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.

joelvh avatar Apr 18 '21 04:04 joelvh

@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.

joelvh avatar Apr 18 '21 19:04 joelvh

@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.

joelvh avatar Apr 18 '21 19:04 joelvh

@seuros I've rebased this

joelvh avatar Apr 26 '21 17:04 joelvh

@seuros just checking to see if this is the route to go or the ActiveModel PR.

joelvh avatar May 10 '21 17:05 joelvh

@seuros will this be merged?

joelvh avatar Aug 23 '21 22:08 joelvh