On 04/11/2016 09:58 AM, Ryan Govostes wrote:
Hi,
I'm a beginner reading the "Basic Relationship Patterns" documentation:
http://docs.sqlalchemy.org/en/latest/orm/basic_relationships.html
The examples are confusing to me because all of the examples use
"Parent" and "Child," which in reality have a Many-to-Many relationship.
It was unclear to me whether the "One To Many" example illustrates "one
parent to many children" or "one child to many parents." Understanding
from the code samples (which are all very similar) presupposes a certain
level of familiarity with how relationships are constructed in SQLAlchemy.
I agree Parent / Child is confusing due to the way one-to-many and
many-to-one are mirror images.
However, the way to think about it, at least how the docs were written,
is that the "Parent" is the object you have "in hand", like "obj =
session.query(MyClass).first()", and "Child" is the object(s) that are
hanging off of it, e.g. "obj.stuff".
That is, Parent/Child are terms given from the object perspective, not
really the relational perspective. That's also how it works out in
many-to-many.
The documentation would be improved by switching to more intuitive
examples. How about
One To Many, Many To One: Countries and Cities
One To One: Capitals and Countries
Many To Many: Organizations and Members
Agree that changing Parent/Child is a good idea though maybe not
something as specific as countries / capitals etc. I wonder if we can
come up with a term that is generic but more descriptive (something like
"Holder" / "Holdee", but not as weird).
It would help to explicitly state the scenario that is being modeled in
each case, even if it appears obvious. The descriptions of the current
examples all immediately jump into technical details of foreign keys,
scalars, and association tables.
Ryan
--
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 [email protected]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at https://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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.