Skip to content

Feature/703 - Adds ability to use nested relationships in existence relationships (has, where_has, doesnt_have, etc) #744

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

Merged
merged 6 commits into from
Jul 2, 2022

Conversation

josephmancuso
Copy link
Member

Closes #703

@josephmancuso josephmancuso changed the title Feature/703 Feature/703 - Adds ability to use nested relationships in existence relationships Jul 2, 2022
@josephmancuso josephmancuso changed the title Feature/703 - Adds ability to use nested relationships in existence relationships Feature/703 - Adds ability to use nested relationships in existence relationships (has, where_has, doesnt_have, etc) Jul 2, 2022
Copy link
Member Author

@josephmancuso josephmancuso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewed

@josephmancuso josephmancuso merged commit 25480d7 into 2.0 Jul 2, 2022
@leannextang
Copy link

Hi there, it seems like still not working...
using dot relation is failed,
image
other one is still working.
image

Is there anything I've done wrong?

@josephmancuso
Copy link
Member Author

what relationship is this? a has many?

@josephmancuso
Copy link
Member Author

nvm I see the issue I will fix soon

@josephmancuso
Copy link
Member Author

This will be fixed in 2.17.2

@leannextang
Copy link

Still get the same error while updated to v. 2.17.2.
Relations list below:

module A:
@has_one('id', 'contract_id')
    def contract(self):
        return models.Contract
@scope
    def abc(self, query):
        return query.where_has("contract.contract_supports", lambda query: query.where("category", "abc"))

module Contract:
@has_many
    def A(self):
        return models.A
@has_many('id', 'contract_id')
    def contract_supports(self):
        return models.ContractSupport

module ContractSupport:
@belongs_to('contract_id')
    def contract(self):
        return models.Contract

@josephmancuso
Copy link
Member Author

Can you give me a better stack trace of the error? I cannot reproduce. Please double check you are updated to the latest

@leannextang
Copy link

leannextang commented Jul 6, 2022

Sure, I'd updated again but still get the same error.
Desktop :

OS: Mac OS Monterey
Version 12.3 with Apple M1
Python Version: 3.10.2

Database I'm using:

Type: Postgres
Version 12.10
Masonite ORM v2.17.2

Here's more detailed stack trace below:

@scope, where_has, related:
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/[email protected]/3.10.2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/opt/homebrew/Cellar/[email protected]/3.10.2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/leanne.tang/.vscode/extensions/ms-python.python-2022.4.1/pythonFiles/lib/python/debugpy/__main__.py", line 45, in <module>
    cli.main()
  File "/Users/leanne.tang/.vscode/extensions/ms-python.python-2022.4.1/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 444, in main
    run()
  File "/Users/leanne.tang/.vscode/extensions/ms-python.python-2022.4.1/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 285, in run_file
    runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
  File "/opt/homebrew/Cellar/[email protected]/3.10.2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 269, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/opt/homebrew/Cellar/[email protected]/3.10.2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/opt/homebrew/Cellar/[email protected]/3.10.2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/leanne.tang/Documents/Projects/Masonite-orm_test/app/services/orator_update.py", line 412, in <module>
    mysql_test_connect()
  File "/Users/leanne.tang/Documents/Projects/Masonite-orm_test/app/services/orator_update.py", line 353, in mysql_test_connect
    abc = models.A.abc().get()
  File "/Users/leanne.tang/Library/Caches/pypoetry/virtualenvs/Masonite-orm_test1-j2JSiUN2-py3.10/lib/python3.10/site-packages/masoniteorm/scopes/scope.py", line 12, in __call__
    return self.fn(instantiated, builder, *args, **kwargs)
  File "/Users/leanne.tang/Documents/Projects/Masonite-orm_test/app/models/A.py", line 99, in abc
    return query.where_has(
  File "/Users/leanne.tang/Library/Caches/pypoetry/virtualenvs/Masonite-orm_test1-j2JSiUN2-py3.10/lib/python3.10/site-packages/masoniteorm/query/QueryBuilder.py", line 1141, in where_has
    last_builder = related.query_where_exists(
TypeError: BaseRelationship.query_where_exists() missing 1 required positional argument: 'callback'

@josephmancuso
Copy link
Member Author

TypeError: BaseRelationship.query_where_exists() missing 1 required positional argument: 'callback'

This is the error that is confusing me because it clearly is not missing in the latest release. https://github.com/MasoniteFramework/orm/blob/2.0/src/masoniteorm/relationships/BaseRelationship.py#L83

@leannextang
Copy link

Looks like you missing a callback arg in QueryBuilder.py ln 1141.
(ln 1146 has it.)
image

@josephmancuso
Copy link
Member Author

that's not the latest code

@leannextang
Copy link

Sorry, I've seen the wrong project...

@leannextang
Copy link

I'll clear the project to test again.

@josephmancuso
Copy link
Member Author

Try to uninstall masonite-orm and reinstall

@leannextang
Copy link

Turns out the weird error happened before was because my poetry virtual environment...
After reset all things up, it seems dot relation still not working,
the column 'category' should be in contract_supports table.

Masonite-orm version:
image

Here's the error message:

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/[email protected]/3.10.2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/opt/homebrew/Cellar/[email protected]/3.10.2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/leanne.tang/.vscode/extensions/ms-python.python-2022.4.1/pythonFiles/lib/python/debugpy/__main__.py", line 45, in <module>
    cli.main()
  File "/Users/leanne.tang/.vscode/extensions/ms-python.python-2022.4.1/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 444, in main
    run()
  File "/Users/leanne.tang/.vscode/extensions/ms-python.python-2022.4.1/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 285, in run_file
    runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
  File "/opt/homebrew/Cellar/[email protected]/3.10.2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 269, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/opt/homebrew/Cellar/[email protected]/3.10.2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/opt/homebrew/Cellar/[email protected]/3.10.2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/leanne.tang/Documents/Projects/Masonite-orm-test/app/services/orator_update.py", line 415, in <module>
    mysql_test_connect()
  File "/Users/leanne.tang/Documents/Projects/Masonite-orm-test/app/services/orator_update.py", line 356, in mysql_test_connect
    abc = models.A.abc().get()
  File "/Users/leanne.tang/Library/Caches/pypoetry/virtualenvs/Masonite-orm-test1-2UYfFVGQ-py3.10/lib/python3.10/site-packages/masoniteorm/query/QueryBuilder.py", line 1936, in get
    result = self.new_connection().query(self.to_qmark(), self._bindings)
  File "/Users/leanne.tang/Library/Caches/pypoetry/virtualenvs/Masonite-orm-test1-2UYfFVGQ-py3.10/lib/python3.10/site-packages/masoniteorm/connections/PostgresConnection.py", line 162, in query
    raise QueryException(str(e)) from e
masoniteorm.exceptions.QueryException: column contracts.category does not exist

@josephmancuso
Copy link
Member Author

Ok I will take a look at this

@josephmancuso
Copy link
Member Author

I created a new issue I will work on it when I have time

@josephmancuso josephmancuso mentioned this pull request Jul 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add dot notation for related relationships in where_has method
2 participants