MasoniteFramework / orm

Masonite ORM is a beautiful Python ORM. It's also a nearly drop in replacement of the Orator ORM
https://orm.masoniteproject.com
MIT License
165 stars 48 forks source link

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

Closed federicoparroni closed 2 years ago

federicoparroni commented 2 years ago

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?

federicoparroni commented 2 years ago

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