[sqlalchemy] Re: Self referencing keys

2007-09-03 Thread voltron

would this work?

users = Table(users, metadata,
Column(id,Integer,primary_key=True),
Column(username,  String(50),unique=True,
nullable=False),
Column(password,  String(255)),
Column(email, String(255),unique=True,
nullable=False),
Column(firstname, String(255)),
Column(lastname,  String(255)),

Column(modifiedby_id, Integer,  ForeignKey(users.id))
Column(modifiedon,DateTime(timezone=True),
default=func.now()),


On Sep 3, 6:50 pm, voltron [EMAIL PROTECTED] wrote:
 Excuse the newbie question, how does one declare a sef-referencing
 key? I would like to have fields modified_by and created_by in my
 users table, the field should refer back to the user id or user name
 in the same table.

 Thanks


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Self referencing keys

2007-09-03 Thread sdobrev

On Monday 03 September 2007 19:57:54 voltron wrote:
 would this work?

 users = Table(users, metadata,
 Column(id,Integer,primary_key=True),
 Column(username,  String(50),unique=True,
 nullable=False),
 Column(password,  String(255)),
 Column(email, String(255),unique=True,
 nullable=False),
 Column(firstname, String(255)),
 Column(lastname,  String(255)),

 Column(modifiedby_id, Integer,  ForeignKey(users.id))
 Column(modifiedon,DateTime(timezone=True),
 default=func.now()),

 On Sep 3, 6:50 pm, voltron [EMAIL PROTECTED] wrote:
  Excuse the newbie question, how does one declare a
  sef-referencing key? I would like to have fields modified_by
  and created_by in my users table, the field should refer back
  to the user id or user name in the same table.
 
  Thanks

yes, foreign key + eventualy use_alter=True if u get cyclic

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Self referencing keys

2007-09-03 Thread sdobrev

A pointing to A, is cyclical dependency.

same as A - B - A.
but in latter case u must choose one of the links to be added later, 
that is use_later=True for ForeignKey.
in former case the table declaration may or may not work without 
use_alter. 
in both cases u need post_update=True for the relation/mapper of the 
loop-closing link of your choice.


On Tuesday 04 September 2007 00:21:06 you wrote:
 Thanks for the reply, what do you mean by cyclic?

 On Sep 3, 9:00 pm, [EMAIL PROTECTED] wrote:
  On Monday 03 September 2007 19:57:54 voltron wrote:
   would this work?
  
   users = Table(users, metadata,
   Column(id,Integer,primary_key=True),
   Column(username,  String(50),unique=True,
   nullable=False),
   Column(password,  String(255)),
   Column(email, String(255),unique=True,
   nullable=False),
   Column(firstname, String(255)),
   Column(lastname,  String(255)),
  
   Column(modifiedby_id, Integer,  ForeignKey(users.id))
   Column(modifiedon,DateTime(timezone=True),
   default=func.now()),
  
   On Sep 3, 6:50 pm, voltron [EMAIL PROTECTED] wrote:
Excuse the newbie question, how does one declare a
sef-referencing key? I would like to have fields
modified_by and created_by in my users table, the field
should refer back to the user id or user name in the same
table.
   
Thanks
 
  yes, foreign key + eventualy use_alter=True if u get cyclic



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~--~~~~--~~--~--~---