You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey guys, I am using the latest version of state_machine. Today I found a problem that my state_machine doesn't trigger the state_machine's :initial lambda codes if I build objects through an association, but does if I use Order.new.
There are two models, Creator and Order, in my application, and there is a has_many association from a creator to many orders. The below shows the definition of my state_machine for Order:
state_machine:initial=>lambda{|order| order.creator_id ? :pending : :unaudited}dostate:unaudited,:pending,:open,:finished,:archived# other things
The result of building order by the new class method:
See? Both built orders have creator_id, but have opposite state.
Then I add breakpoint to the lambda, I found that the lambda will be run if I build objects through new method, and will never be trigger if through an association.
Could you help me? Thanks in advance.
The text was updated successfully, but these errors were encountered:
Hey guys, I am using the latest version of
state_machine
. Today I found a problem that my state_machine doesn't trigger the state_machine's:initial
lambda codes if I build objects through an association, but does if I useOrder.new
.There are two models,
Creator
andOrder
, in my application, and there is a has_many association from a creator to many orders. The below shows the definition of my state_machine for Order:The result of building order by the
new
class method:Well, it goes well as what I expect, but, if I build a new order by a creator, it will have something wrong:
See? Both built orders have
creator_id
, but have opposite state.Then I add breakpoint to the lambda, I found that the lambda will be run if I build objects through
new
method, and will never be trigger if through an association.Could you help me? Thanks in advance.
The text was updated successfully, but these errors were encountered: