Hi,

you should write to sqlalchemy's mailing list :

http://www.sqlalchemy.org/support.html#mailinglist


You'll find a definition of foreign keys here (it's an sql functionnality):
http://docs.sqlalchemy.org/en/rel_0_9/core/constraints.html#defining-foreign-keys


For the relationship function, you'll find it there (it's specific to
sqlalchemy's orm):
http://docs.sqlalchemy.org/en/rel_0_9/orm/relationships.html#one-to-many


Briefly, declaring the relationship you can access the parent's children
this way (supposing parent is an instance of the Parent class):

for child_obj in parent.children:
    print child_obj.id

If you don't declare the relationship, you will not have the children
attribute.



Le 23/03/2014 19:20, luoyingshenfu a écrit :
> Hello, everyone, I am starting to use sqlalchemy now and really got
> frustrated in understanding the purpose of relationship().
>
> For example, if I make a model  with a foreign key  like the one in
> sqlalchemy's official docs:
>
>
> class Parent(Base):
>     __tablename__ = 'parent'
>     id = Column(Integer, primary_key=True)
>     children = relationship("Child")
>
> class Child(Base):
>     __tablename__ = 'child'
>     id = Column(Integer, primary_key=True)
>     parent_id = Column(Integer, ForeignKey('parent.id'))
>
>
> so ,when I write 'parent_id=Column(Integer,ForeignKey('parent.id')), ,
> have this statement already establish the relationship between child
> and parent? because parent is the table name and they all live in one
> database, so child can automatically fetch the data from parent.id,
> right? so why bother with the relationship(), I mean, if I don't write
> the relationship(), what will happen? Child can not find the parent
> table and fetch its ID? I am really confused here
> -- 
> You received this message because you are subscribed to the Google
> Groups "pylons-discuss" 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 http://groups.google.com/group/pylons-discuss.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" 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 http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/d/optout.

Reply via email to