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

When used with ActiveRecord, AASM does not check that fields are in the backing db #152

Closed
michaeldickens opened this issue Jul 15, 2014 · 6 comments
Assignees

Comments

@michaeldickens
Copy link

I recently encountered a bug in some code I wrote where I was attempting to access an AASM state from the backing database associated with an ActiveRecord. I hadn't migrated the database, so AASM couldn't find the column in the database. Instead of returning a helpful error, it said, NoMethodError: undefined methodtype' for nil:NilClass. I discovered that this happens in active_record_persistence.rb:131 whenself.class.columns_hash[self.class.aasm_column.to_s].typecallstypeon anil` value. It would be helpful if AASM checked that the field was in the database before trying to operate on it.

@alto alto self-assigned this Aug 15, 2014
@fabioperrella
Copy link

@alto I can try to do this. What branch should I use?

@alto
Copy link
Member

alto commented Jul 30, 2015

@fabioperrella ?

@fabioperrella
Copy link

@alto I was looking for some issue to contribute, if you want, I will try to send you a pull request. I asked in what branch should I work on it ?

@alto
Copy link
Member

alto commented Jul 30, 2015

@fabioperrella Ah, now I understand. There are two main branches currently worked on, master and multiple_state_machines_per_class. I would recommend to branch from master, because the multiple one is changing quite a lot.

Thanks for your help. I really appreciate this!

@fabioperrella
Copy link

@michaeldickens I tryed to reproduce your error but I couldn't. I created a class using aasm and didn't migrated the DB (the column aasm does not exist), then when I called the method .aasm_state, it raised the error NoMethodError: undefined method `aasm_state' for #<Account id: nil, name: "aa">
I used the last stable version of aasm (4.2.0) and rails 4.2.3
Which versions were you using?

anilmaurya added a commit to joshsoftware/aasm that referenced this issue Oct 3, 2015
When using enum for state column and enum config not set explicitly,
if column is not present in database then "NoMethodError: undefined
method 'type' for nil:NilClass" was raised for transitions which is
hard to debug.
Fix aasm#152
@alto alto closed this as completed in #265 Jan 7, 2016
alto added a commit that referenced this issue Jan 7, 2016
@alto
Copy link
Member

alto commented Jan 7, 2016

@michaeldickens I just released version 4.6.0 including @anilmaurya's patch. Please re-open if it doesn't work.

LeeChSien pushed a commit to LeeChSien/aasm that referenced this issue Jan 8, 2016
When using enum for state column and enum config not set explicitly,
if column is not present in database then "NoMethodError: undefined
method 'type' for nil:NilClass" was raised for transitions which is
hard to debug.
Fix aasm#152
LeeChSien pushed a commit to LeeChSien/aasm that referenced this issue Jan 8, 2016
LeeChSien pushed a commit to LeeChSien/aasm that referenced this issue Jan 9, 2016
When using enum for state column and enum config not set explicitly,
if column is not present in database then "NoMethodError: undefined
method 'type' for nil:NilClass" was raised for transitions which is
hard to debug.
Fix aasm#152
LeeChSien pushed a commit to LeeChSien/aasm that referenced this issue Jan 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants