On Sep 28, 2010, at 3:28 PM, Mark Erbaugh wrote:

> I have a self-referential table:
> 
> class L3Acct(BASE):
> 
>    __tablename__ = 'l3_acct'
> 
>    id = Column(Integer, primary_key=True)
>    parent = Column(ForeignKey('l3_acct.id'))
> 
>    [....]
> 
> 
> When adding new rows to the table, the id field is not assigned a value until 
> the data is actually written to the database.  When adding several rows to a 
> session object is there a way for a new row to reference a row that has 
> previously been added in the same batch, but hasn't been assigned an id yet?

sure, you use the relation() function at the class level to associate L3Acct 
instances with their parent instance, and establish the linkage at the object 
level, rather than the pk/fk level.

This would be many-to-one, make sure you follow whats at 
http://www.sqlalchemy.org/docs/orm/relationships.html#adjacency-list-relationships
 carefully (including the remote_side flag).   Those are the 0.6 docs but 
configuration for 0.5.8 is the same (except relationship() is relation()).




> 
> I'm using SQLAlchemy 0.5.8.
> 
> Thanks,
> Mark
> 
> -- 
> 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