Comments (6)
First off, thank you so much for including the SQL, makes debugging so much easier :)
Since a product can have multiple items, the value of the aggregate functions has meaning and that is why you get meaningful results. The big question is what you expect "price1" to be. By the "?" interpolation I gather you're using sqlite -- trying this query in postgresql would most likely not work since it is a bit stricter.
from peewee.
Yes, it's a bit contrived :)
In the case of the SQLite 3.7.11 it would return the same price as
MAX(price1). Also, I'm not extremely familiar with PostgreSQL, but I
believe the latest versions allow such queries also.
I'm totally fine if you don't want to allow this. It was just a
little confusing, because I was able to provide a list of fields to
Product, but not to Item. I do agree though, price1 isn't really
useful.
Sort of related, would R() work in this case? For example:
R('GROUP_CONCAT(image) AS image')
from peewee.
Yeah, in my opinion this is one of those things that give ORMs a bad rap. For a detailed description of a possible solution, check out https://groups.google.com/forum/?fromgroups#!topic/peewee-orm/RLd2r-eKp7w
You're doing an inner join but you want, in a sense, a right join on item and peewee doesn't support this...and as you said, the value of price1 is "indeterminate" but should probably be a list. The way I would fix this is to query Item and group by product. I'm not familiar with the group_concat function but would be interested in learning more.
from peewee.
Thanks!
Btw, I didn't realize there was a peewee forum!
from peewee.
If you want to try this out, its kidn of hacky but might do what you want:
http://peewee.readthedocs.org/en/latest/peewee/querying.html#speeding-up-simple-select-queries
from peewee.
That works great, thank you! Good choice in method name :)
from peewee.
Related Issues (20)
- Connection Already Closed HOT 8
- Select from subquery including a case statement HOT 1
- Problem with multi threading with Pool.map HOT 2
- MySQL database throws exception when create_tables is called HOT 1
- Encountering TypeError with heappush HOT 9
- Implement new parameter db_default sets a database-computed default value HOT 1
- Join on multiple fields work but call to field value is queried again HOT 1
- Update branch `feature/psycopg3-fixes` HOT 1
- peewee's where condition doesn't seem to support the is operator. HOT 1
- Outdated link to APSW
- pop an expression from where clause (unscoping) HOT 1
- Document Page Http ERROR .
- model to dict , alias problem HOT 1
- [Question] Local model, how make HOT 1
- [Question] Sum order by HOT 1
- datetime invoke HOT 2
- Update branch `feature/psycopg3-fixes` HOT 6
- How to convert the query cursor to a list of models HOT 1
- GROUP BY field by alias. exists() method exception HOT 1
- The `Model` class should provide a `__str__()` for heuristic string representation of the model object HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from peewee.