GithubHelp home page GithubHelp logo

Comments (11)

billstickers avatar billstickers commented on May 13, 2024

just got bitten by this bug myself.

from aasm.

jaryl avatar jaryl commented on May 13, 2024

Yeah, and you'd think that more people would be experiencing this. There are 556 watchers.

from aasm.

jaryl avatar jaryl commented on May 13, 2024

I forked the repo and fixed the error @ http://github.com/Jaryl/aasm/tree/master. Now, how does this thing work, should I leave it at this or do I submit a pull request or what?

from aasm.

lwu avatar lwu commented on May 13, 2024

Note that the newest documentation (or at least the source as of version 2.1.5) now just says "Writes state to the state column and persists it to the database", which means that your state will not be persisted unless the object validates.

from aasm.

jaryl avatar jaryl commented on May 13, 2024

Iwu, you are right. You may want to follow the discussion here:
http://rubyist.lighthouseapp.com/projects/13207/tickets/18-state-transitions-do-not-persist-to-db-in-activerecord-models

from aasm.

halorgium avatar halorgium commented on May 13, 2024

My belief is that if the model is in a state which is currently invalid, the transition should fail if only to prevent further invalidation.
Even if the state transition would make the model valid, the potential of having an invalid model persisted only creates more confusion.

Perhaps a solution would be to check if the model is valid before attempting transitions.

from aasm.

jaryl avatar jaryl commented on May 13, 2024

I'm currently using state_machine in my projects, which provides facility to validate/invalidate state changes, in case any of you are shopping around.

from aasm.

alto avatar alto commented on May 13, 2024

So, what do you expect to happen? Returning false if trying to change the state of an invalid object? Or do you prefer to throw an exception?

from aasm.

halorgium avatar halorgium commented on May 13, 2024

I would expect that a state change would either raise an exception or return false.
Just like in AR::Base#update_attributes! vs. AR::Base#update_attributes.

The main thing is that the transition did not occur.

from aasm.

alto avatar alto commented on May 13, 2024

Okay, I see. If the state is not changed, then it's a bug, and I'll fix it soon.

from aasm.

alto avatar alto commented on May 13, 2024

I just released version 3.0.2, where I added a switch to the aasm configuration (:skip_validation_on_save) to make sure that states are stored to the database even if the model is invalid. Look at the readme on https://github.com/rubyist/aasm, section 'Persistence example' how to apply it.

from aasm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.