8000 Filtering by `orm.Set` · Issue #746 · ponyorm/pony · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Filtering by orm.Set #746

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

Open
Real-Gecko opened this issue Apr 29, 2025 · 0 comments
Open

Filtering by orm.Set #746

Real-Gecko opened this issue Apr 29, 2025 · 0 comments

Comments

@Real-Gecko
Copy link
Real-Gecko commented Apr 29, 2025

I have following models

class Family(db.Entity):
    _table_ = "families"

    id = orm.PrimaryKey(int, auto=True)
    persons = orm.Set("Persons")

class Person(db.Entity):
    _table_ = "persons"

    id = orm.PrimaryKey(int, auto=True)
    family = orm.Required(Family, column="family_id")
    info = orm.Optional(orm.Json)

Now I need to filter Family object by persons where info meets certain criteria, like in following query:

select
  distinct(f.*)
FROM
  families f
  join persons p on p.family_id = f.id
where
  p.info ->> 'last_name' = 'Connor'

How can I achieve this with Pony if where clause is optional?
I tried like this:

# filter may be "p.info ->> 'last_name' = 'Connor'" or maybe `None`
query = Family.select()
if filter:
    query.filter(lambda f: p for p in f.persons if raw_sql(filter))

But I get Undefined name f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0