aasm / aasm/aasm

`or` not working -- relation must be structurally compatible

Open
#498 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
5.2k
Forks
644
PR merge metrics
No merged PRs in 30d

Description

If I try to execute a state's scope inside an or statement, it doesn't work properly.

Model.any_non_state_scope.or(Model.state_scope)

(For instance, Todo.where(description: value).or(Todo.unchecked) if unchecked is a state)

That causes this error:

*** ArgumentError Exception: Relation passed to #or must be structurally compatible. Incompatible values: [:references]

I can fix this by using a state scope outside of the or as well:

Model.any_state_scope.or(Model.state_scope)

(For instance, Todo.checked.or(Todo.unchecked) if checked and unchecked are states)

But that's obviously not ideal.

This also DOES NOT work like this:

Model.where(state: any_state).or(Model.state_scope)

It has to directly use the aasm scope methods or it's seen as incompatible.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the two Model#or examples from the issue and inspect the AASM state-scope integration with Rails relations, especially the structural compatibility and references values. Done means a relation such as Todo.where(description: value).or(Todo.unchecked) works without the incompatibility error while the existing state-scope examples continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.