On Feb 24, 2010, at 6:14 AM, flya flya wrote:

> Yes, this is what I wonder, but my code use orm, declarative_base(), not 
> mapper, I write these code follow the document's example, it can't work too, 
> what's wrong with my code?
> 
> Base = declarative_base()
> class Page(Base):
>    __tablename__ = 'pages'
>    id = Column(Integer, primary_key=True)
>    parent_id = Column('parent_id', Integer, ForeignKey('pages.id'))
>    
>    children = relation('Page')
>    parent = relation('Page', remote_side=['pages.c.id'])

no quotes unless the [] are in there as well.  See this FAQ entry:  
http://www.sqlalchemy.org/trac/wiki/FAQ#ImusingDeclarativeandsettingprimaryjoinsecondaryjoinusinganand_oror_andIamgettinganerrormessageaboutforeignkeys.




> 
> when insert a data, raise the error information:
> raise sa_exc.ArgumentError("Relation %s could not determine any local/remote 
> column pairs from remote side argument %r" % (self, self.remote_side))
> sqlalchemy.exc.ArgumentError: Relation Page.parent could not determine any 
> local/remote column pairs from remote side argument 
> set([<sqlalchemy.sql.expression.ColumnClause at 0xa17690c; pages.c.id>])
> 
> 
> On Wed, Feb 24, 2010 at 3:39 PM, Oliver Beattie <oli...@obeattie.com> wrote:
> > You probably want to take a look at
> > http://www.sqlalchemy.org/docs/05/mappers.html#adjacency-list-relationships
> >
> > On Feb 23, 5:42 pm, flya flya <flyafl...@gmail.com> wrote:
> >> here is code:
> >>
> >> Base = declarative_base()
> >> class Page(Base):
> >>    __tablename__ = 'pages'
> >>    id = Column(Integer, primary_key=True)
> >>    parent_id = Column('parent_id', Integer, ForeignKey('pages.id'))
> >>
> >>   children = relation('Page', backref='parent')
> >>
> >> I get error information:
> >> sqlalchemy.exc.ArgumentError: Page.children and back-reference
> >> Page.parent are both of the same direction <symbol 'ONETOMANY>.  Did
> >> you mean to set remote_side on the many-to-one side ?
> >>
> >> when change the code
> >> children = relation('Page', backref='parent')
> >> to
> >> childen = relation('Page')
> >> It can work , but I can  only get 'children' no  'parent' from a Page 
> >> instant.
> >
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "sqlalchemy" group.
> > To post to this group, send email to sqlalch...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > sqlalchemy+unsubscr...@googlegroups.com.
> > For more options, visit this group at 
> > http://groups.google.com/group/sqlalchemy?hl=en.
> >
> >
> 
> 
> 
> -- 
> http://www.flyaflya.com
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalch...@googlegroups.com.
> To unsubscribe from this group, send email to 
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to