Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State of new object with ActiveRecord #191

Closed
kaluznyo opened this issue Dec 3, 2014 · 8 comments
Closed

State of new object with ActiveRecord #191

kaluznyo opened this issue Dec 3, 2014 · 8 comments
Assignees
Labels

Comments

@kaluznyo
Copy link

kaluznyo commented Dec 3, 2014

Hi,

I don't know if it's a bug or a bad comprehension of process

With this code:

class ProductSalesImport < ActiveRecord::Base
  include AASM
  aasm column: :state do

    state :picking, initial: true
    state :enqueued
end

@product_sale_import = ProductSalesImport.new 
@product_sale_import.state => nil

The state should be 'picking' ?

@alto alto self-assigned this Dec 3, 2014
@hasghari
Copy link

hasghari commented Dec 4, 2014

I encountered this problem today as well. I find that it's best to not check directly against the database column to retrieve the current state. The recommended approach is:

@product_sale_import.aasm.current_state

Once persisted, the state column will reflect the correct value.

@alto alto added the bug label Dec 4, 2014
@alto
Copy link
Member

alto commented Dec 4, 2014

@hasghari Yes, it's currently exactly like you said. But the more I think about it, the more incomplete this approach seems to me.

@kaluznyo I now consider this a bug, and will find a solution to it.

alto added a commit that referenced this issue Dec 4, 2014
@alto
Copy link
Member

alto commented Dec 4, 2014

Will release a patch soon (will be 4.0.4 then). Feel free to check out the latest master branch (includes just one other bugfix for a namespace collision).

@kaluznyo
Copy link
Author

kaluznyo commented Dec 5, 2014

Work fine with master and rails 4.2.0.rc1

@alto
Copy link
Member

alto commented Dec 5, 2014

I just released version 4.0.4, which includes the change.

@alto alto closed this as completed Dec 5, 2014
@hlin-blurb
Copy link

I'm on version 4.1.0, and I see this bug:

user = User.new
user.aasm.current_state # :pending
user.save # true
user.aasm.current_state # nil

@Danielpk
Copy link

I'm at version 4.1.0 and still get same error:

  aasm column: :state, create_scopes: false do
    state :draft, initial: true
    state :bank_info
    state :complete

    event :next_step do
      transitions from: :draft, to: :bank_info
      transitions from: :bank_info, to: :complete
    end
  end

Also my object don`t transition to next state:
Ex:

project = Project.new
project.state # :nil
project.aasm.current_state # :draft
project.next_step #true
project.state # :nil
project.aasm.current_state # :draft .. should be :bank_info

@Danielpk
Copy link

Never mind what i said, there was one module overwriting the state method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants