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

`on` method should affect only the `Model` instance #726

Closed federicoparroni closed 2 years ago

federicoparroni commented 2 years ago

Describe the bug In the Model class we have the on method defined both in the __passthrough__ list and a class method: https://github.com/MasoniteFramework/orm/blob/0ed95841f5cc52f8b8a7d443be1119a0e6e13a6d/src/masoniteorm/models/Model.py#L183 https://github.com/MasoniteFramework/orm/blob/0ed95841f5cc52f8b8a7d443be1119a0e6e13a6d/src/masoniteorm/models/Model.py#L1008-L1011

Given this fact, it seems that the classmethod is always called, see the following example:

connection_name = "example-conn"
model = MyModel().on(connection_name)
print(model.builder.connection)    # example-conn
print(MyModel.__connection__)      # example-conn

Expected behavior The class attribute __connection__ should not be changed. I think the correct behaviour should be to passthrough the on method towards the QueryBuilder instance, so removing the class method or using another name for it (e.g.: global_on).