On 5/19/15 8:57 AM, Richard Gerd Kuesters wrote:
hi!
this may be a weird question, but is there a way i can restrict the
number of children in a relationship? not by limit ...
how is that different? Anytime in SQL you want to get only the first N
of M, LIMIT or its equivalents must be involved.
two options are:
1. write the exact SQL for the primary + relationship you want, then use
contains_eager() to specify it as a collection load. the SQL has to be
along the lines of "SELECT * FROM primary LEFT OUTER JOIN secondary
WHERE secondary.id IS NULL or secondary.id IN (select id FROM secondary
AS sec_2 LIMIT N WHERE sec_2.primary_id=secondary.primary_id)
2. load the collections individually:
from sqlalchemy.orm.attributes import set_committed_value
for item in things:
child_items = sess.query(Child).with_parent(item).limit(N).all()
set_committed_value(item, "child_items", child_items)
scenario: i have a one to many rel, where the parent have 3 values
(row, column, depth) that creates a max child count of row * column *
depth (yes, like the 3d stuff) ... so, count(child) >= max_child, this
sort of stuff.
if i could pull of postgres specific constraint for this, even better ...
best regards,
richard.
--
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to sqlalchemy+unsubscr...@googlegroups.com
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.