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

BelongsTo relation has wrong amount of QueryBuilder arguments. #767

Closed
leannextang opened this issue Jul 19, 2022 · 3 comments
Closed

BelongsTo relation has wrong amount of QueryBuilder arguments. #767

leannextang opened this issue Jul 19, 2022 · 3 comments
Labels
bug An existing feature is not working as intended

Comments

@leannextang
Copy link

This works at v2.17.2, but fails at v2.18.1.

Steps to reproduce the behavior:

  1. Set module Contract:
class Contract(Model):
...
    @belongs_to
    def company(self):
        return models.Company
  1. Set module Company:
class Company(Model):
...
    @has_many('id', 'company_id')
    def contract(self):
        return models.Contract
 
    @scope
    def active(self, query):
        return query.where("status", 1)
  1. Call models.Contract.with_(('company' :models.Company.active()}).first().uid)

Error Message:
image

Desktop (please complete the following information):

  • OS & FAQ :

image

Versions:

  • Database: Postgres 12.11
  • Masonite ORM v2.18.1
@leannextang leannextang added the bug An existing feature is not working as intended label Jul 19, 2022
@josephmancuso
Copy link
Member

models.Contract.with_({"company": models.Company.active()})

This is not the proper usage of this feature. You have to use a lambda expression that takes a query builder instance.

I believe you should be able to do something like:

models.Contract.with_({"company": lambda q: q.active()})

@josephmancuso
Copy link
Member

Please see docs here https://orm.masoniteproject.com/models#dynamic-relationships

@leannextang
Copy link
Author

Thank you for the information,
we will check how to fix the legacy code here.

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

No branches or pull requests

2 participants