Giter Club home page Giter Club logo

Comments (6)

coleifer avatar coleifer commented on May 22, 2024

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.

jdearl avatar jdearl commented on May 22, 2024

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.

coleifer avatar coleifer commented on May 22, 2024

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.

jdearl avatar jdearl commented on May 22, 2024

Thanks!
Btw, I didn't realize there was a peewee forum!

from peewee.

coleifer avatar coleifer commented on May 22, 2024

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.

jdearl avatar jdearl commented on May 22, 2024

That works great, thank you! Good choice in method name :)

from peewee.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.