On 7/15/15 4:40 PM, Юрий Пайков wrote:
Ok, that is clear now.
Eagerloading of tables occurring more than once in a query
is a bit confusing for me as it is not well-documented,
for example that contains_eager() needs alias=<parameter>
in order to work properly for a second occurrence of a table.
If I might I would advise you to shed some light on the usage
in a documentation.
it really comes down to an understanding of the basic concept. The
SQL itself must return the correct results. You cannot refer to a
table twice in the same SQL statement in two different FROM
contexts; all but one of them must be aliased for them to be handled
separately. contains_eager() mererly refers the ORM to the
particular columns in the result set that represent the data for
this collection.
If you turn on echo='debug' in your create_engine() statement, you
can watch the rows as they come in. To load a series of B rows,
which also contain a series of additional B objects represented via
JOIN or LEFT OUTER JOIN, requires aliasing.
OK, moving on
When using
.join(relation,
aliased=True)
it is stated that next
.fliter() call will refer to
the second occurrence (unless
.reset_joinpoint() is
called).
aliased=True is an old feature that I think is more confusing than
it is worth for end-user use of query(). I'd not recommend using
it unless you have some case where it is absolutely necessary.
Here I
have an example of similar behavior. Consider my slightly
modified example.
it seems contains_eager(), when given not the full
path from the first occurrence(B-A-A-B-C) but rather only the
portion of path from the last mention of table(B-C), populates
the collection with the data from the latest mentioned
instance of that table
That seems incorrect. There is no join from B->cs stated here,
there is only a join from second_B->cs. Therefore
contains_eager() should be given second_B.cs, not B.cs. But also,
yes, the full path of contains_eager() must be stated here, because
otherwise the query will never populate B.as_, or A.children, or
A.bs, and therefore never get to B.cs; those columns are thrown
away.
Is it the desired outcome or should it be considered a bug?
Could this pattern change in future?
That the eager loading system requires full explicitness in order to
know what to do is exactly why it is so flexible.
And, as always, thank you for you patience and attention
brought to my problem
my pleasure!