On Fri, Jun 13, 2008 at 1:03 AM, lilo <[EMAIL PROTECTED]> wrote:
>
> Can string field "username" in table User be foreign key to Post table
> just like integer foreign keys?
Of course. That's what the belongs_to relationship will do for you.
>
> On Jun 12, 11:37 am, lilo <[EMAIL PROTECTED]> wrote:
>> how do you define composite primary key made up of 1 foreign key
>> (username, a text field from user table) and id field(integer field)
>> from post table?
>>
>> can you have attribute based syntax and dsl based syntax together for
>> a model? If I use attribute based syntax to declare ManyToOne(User)
>> field in model Post, that means it can only deal with integer id
>> field.
>>
>> Here are my models:
>>
>> # primary key for user model is a text field. (There is no integer id
>> field)
>> class User(Entity):
>> using_options(tablename='user')
>> username = Field(String(30), primary_key = True, nullable =
>> False, unique=True)
>>
>> class Post(Entity):
>> using_options(tablename='post')
>> # id and username( foreign key), are composite primary key for the
>> Post table
>> id = Field(Integer, primary_key = True, autoincrement = True,
>> nullable = False)
>> belongs_to('user', of_kind = 'User', inverse = 'post',
>> column_kwargs = {'primary_key': True, 'nullable': False})
>> using_table_options(UniqueConstraint('id', 'user'))
> >
>
--
Gaƫtan de Menten
http://openhex.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"SQLElixir" 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/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---