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
178 stars 49 forks source link

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

Open BSN4 opened 2 years ago

BSN4 commented 2 years ago

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?

BSN4 commented 2 years ago

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