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'])*
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 <[email protected]> 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 <[email protected]> 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 [email protected].
> To unsubscribe from this group, send email to
[email protected]<sqlalchemy%[email protected]>
.
> 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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.