On 5/19/15 10:54 AM, Richard Gerd Kuesters wrote:
thanks Mike!
when i stated about the limit, it was because it must not be taken as
a parameter for any query, which "select * from blah" and "select *
from bla limit N" should be return the same exactly number of rows,
including where filters and so on. it is something like a "physical"
rule, where my parent is (really) a box and the children its items
(so, i cannot put more items then the box's limit).
either way, creating a relationship with limit *can* provide me that
sort of behaviour?
I don't understand what "the behavior" is here. No LIMIT, yet there is
a "limit". An assertion? I have no idea what you mean. The
relationship 1. emits SQL 2. loads the results into objects. Are we
talking about 1. or 2. ?
i mean, i'm just asking this because it may be already done by
someone. if not, that's not a problem -- i'll have to managed
something by myself :)
ps: sorry for my bad english, sometimes i can't make understandable
questions :)
best regards,
richard.
On 05/19/2015 11:16 AM, Mike Bayer wrote:
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
<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
<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.