benzelano / test_lh_import

1 stars 0 forks source link

State new messes up relations in DataMapper #59

Closed benzelano closed 13 years ago

benzelano commented 13 years ago

bterkuile opened this issue

I don’t know what the problem is, but having statemachine with initial => ’new’ for DataMapper gives problems in associations. Info:

original LH ticket

This ticket has 0 attachment(s).

benzelano commented 13 years ago

Matt commented

Same experience here (I finally checked here to see if anyone had reported the bug. Changing the initial state to something other than :new fixed the problem for me). Using ruby 1.9.2 p0, state_machine gem (0.9.4), datamapper 1.0.2. Not using Rails or dm-rails.

benzelano commented 13 years ago

Hey guys -

Thanks for reporting this issue. I believe the only way to fix this is to change your state machine to either use a different state name or namespace the machine. However, state_machine should throw an exception indicating that the state name cannot be used since it conflicts with methods already defined on the class. I’ll look into making those situations a little louder.

benzelano commented 13 years ago

(from [d695c8e68a2179ca3dbf9dd3f06cb8368ad4a83d]) Allow fallback to generic state predicates when individual predicates are already defined in the owner class [#59 state:resolved] Generate warnings when conflicting state / event names are detected https://github.com/pluginaweek/state_machine/commit/d695c8e68a2179ca3dbf9dd3f06cb8368ad4a83d

benzelano commented 13 years ago

Good news: I added a fallback mechanism such that you can now use states like :new even when the associated state predicate (new?) already exists in the class. This will no longer break your DataMapper state machines.