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

cannot Using .add_select() with .with_() #813

Open
BSN4 opened this issue Oct 13, 2022 · 1 comment
Open

cannot Using .add_select() with .with_() #813

BSN4 opened this issue Oct 13, 2022 · 1 comment
Labels
bug An existing feature is not working as intended

Comments

@BSN4
Copy link
Contributor

BSN4 commented Oct 13, 2022

Describe the bug
I have a HasMany relation which I am calling it by with_() and I want to have .addselect() but it throws error getattr(): attribute name must be string ... you can only have .addselect() or with_() in your query but not both

To Reproduce

user = User.find(1)
user.related('posts').with_({
  'images': lambda q: q.where_null('drafted_at')
}).add_select("drafted_count", lambda q: (
   q.count("*").from_("images").where_column("images.user_id", "users.id").where_not_null('drafted_at')
 )).get()

Expected behavior
What do you believe should be happening?

It should work

What database are you using?

  • Type: SQLite
  • Masonite ORM : latest
@BSN4 BSN4 added the bug An existing feature is not working as intended label Oct 13, 2022
@BSN4
Copy link
Contributor Author

BSN4 commented Oct 14, 2022

so I found a soultion if you add .add_select() to you query make sure you define .select('*').

I think its still a bug where add_select() wipe out all selects and leaves only the new one

also it would be nice if it throws obvious error Couldn't find relation.id

@josephmancuso josephmancuso changed the title Using .add_select() with .with_() cannot Using .add_select() with .with_() Oct 6, 2023
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

1 participant