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

No easy way to find previous state #348

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

marclerodrigues
Copy link

Closes #263

Before:

previous_state = project.transitions.where(most_recent: false).last.to_state || project.initial_state

After:

project.last_transition.from_state

@marclerodrigues marclerodrigues force-pushed the add-from-state-to-transition-history branch 2 times, most recently from dfb54f6 to 669a596 Compare May 27, 2019 23:27
Copy link
Contributor

@danwakefield danwakefield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea.

Is it possible to test if this gracefully falls back when a table does not have the from_state column?
It'd be great if we didn't make table migrations required.

@dmagliola
Copy link

Could we have a from_state property on the Transition model, which does something like this, instead of adding a column?

def from_state
  transitions.where(id < self.id).last.to_state
end

Basically, i'm trying to avoid adding the redundant column. If the concern here is the performance hit of an extra DB call, rather than the non-obvious code one needs to write to get the "next-to-last" transition, then this obviously doesn't help.

@marclerodrigues
Copy link
Author

@dmagliola The point of this PR is getting the previous state without another DB call.

@marclerodrigues
Copy link
Author

@danwakefield I'm afraid this would be a breaking change since I'm making that a required value when transitioning.

What do you think about adding the from_state in the metadata? This way we wouldn't need a new column and would also save another DB call.

We could do that as a "workaround" and push it in a minor change and make the from_state column required in future major versions. Let me know your thoughts on this.

@dmitry
Copy link
Contributor

dmitry commented Jan 22, 2021

What about initial state? last_transition returns only second and next states.

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

Successfully merging this pull request may close these issues.

No easy way to find previous state
4 participants