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

Querying trashed model does not work #330

Closed
girardinsamuel opened this issue Jan 25, 2021 · 2 comments · Fixed by #349
Closed

Querying trashed model does not work #330

girardinsamuel opened this issue Jan 25, 2021 · 2 comments · Fixed by #349
Labels
bug An existing feature is not working as intended medium These issues are geared for people who have contributed to the project before Models These issues relate to the Model portion of the ORM

Comments

@girardinsamuel
Copy link
Contributor

girardinsamuel commented Jan 25, 2021

On a soft deletable User model I get this:

user = User.with_trashed().find(self.request.param("user"))
# == class model 'User' has no attribute with_trashed

I observe also this error on the line shown in ORM documentation:

>>> from app.User import User
>>> User.with_trashed().all()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/samuel/.pyenv/versions/pingcrm_masonite/lib/python3.9/site-packages/masoniteorm/models/Model.py", line 40, in __getattr__
    return getattr(instantiated, attribute)
  File "/Users/samuel/.pyenv/versions/pingcrm_masonite/lib/python3.9/site-packages/masoniteorm/models/Model.py", line 510, in __getattr__
    raise AttributeError(f"class model '{name}' has no attribute {attribute}")
AttributeError: class model 'User' has no attribute with_trashed

But the soft deletes mixin is working otherwise. For example I can do this:

User.where("id", 4).count() #== 0
User.where("id", 4).with_trashed().count() # == 1

Here is my model: https://github.com/girardinsamuel/pingcrm-masonite/blob/fix/3.0/app/User.py

@josephmancuso
Copy link
Member

interesting. We may need to also bind the macro to the current model as well 🤔

@josephmancuso
Copy link
Member

josephmancuso commented Jan 25, 2021

Or another solution would be to append the pass through to the model which append the __passthrough__ attribute. Either solution needs to be entirely done in that SoftDeleteMixin class. (or maybe even the SoftDeleteScope class)

@josephmancuso josephmancuso added bug An existing feature is not working as intended Models These issues relate to the Model portion of the ORM medium These issues are geared for people who have contributed to the project before labels Jan 25, 2021
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 medium These issues are geared for people who have contributed to the project before Models These issues relate to the Model portion of the ORM
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants