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

Scopes with the same name from different models cannot coexist #787

Closed
federicoparroni opened this issue Sep 1, 2022 · 1 comment · Fixed by #788
Closed

Scopes with the same name from different models cannot coexist #787

federicoparroni opened this issue Sep 1, 2022 · 1 comment · Fixed by #788
Labels
bug An existing feature is not working as intended

Comments

@federicoparroni
Copy link
Contributor

Describe the bug
You cannot declare scopes with the same name in different models. If you do that, the last declared one overwrites the previous ones.

To Reproduce

class Cat(Model):
    # suppose Cats table has only the 'cat_color' column
    @scope
    def filter_color(self, query, op='=', value=''):
        return query.where('cat_color', op, value)

class Dog(Model):
    # suppose Dogs table has only the 'dog_color' column
    @scope
    def filter_color(self, query, op='=', value=''):
        return query.where('dog_color', op, value)

cat = Cat.filter_color("=", "white").first()  # the wrong scope is called (from the Dog class)

Expected behavior
Scopes should be retrieved from the correct class in which they are declared.

What database are you using?

  • Type: MySQL
  • Version: 5.7
  • Masonite ORM: v2.18.4
@federicoparroni federicoparroni added the bug An existing feature is not working as intended label Sep 1, 2022
@federicoparroni
Copy link
Contributor Author

@josephmancuso I provided a quick solution in the PR, please check it and say your suggestions

josephmancuso added a commit that referenced this issue Sep 11, 2022
#787 - Index scopes by class in which they are declared
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An existing feature is not working as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant