for the record,

default=db(db.owner.isdefault==True).select().first().id

appears to work, note the addition of "ìd".

Thanks
Vincent


On Thursday, June 7, 2012 9:49:30 PM UTC-5, Massimo Di Pierro wrote:
>
> db(db.owner.isdefault=True).select()
>
>
> should be
>
>
> db(db.owner.isdefault==True).select()
>
>
> On Thursday, 7 June 2012 16:48:57 UTC-5, Vincent wrote:
>>
>> Thanks for the suggestion.
>> It returns the following error:
>> SyntaxError: keyword can't be an expression
>>
>> On Thursday, June 7, 2012 4:26:03 PM UTC-5, Derek wrote:
>>>
>>> Have you tried this:
>>>
>>> db.define_table('dog', 
>>> Field('name','string'),Field('owner',db.owner,default=db(db.owner.isdefault=True).select().first()))
>>>
>>>
>>> On Thursday, June 7, 2012 2:20:30 PM UTC-7, Vincent wrote:
>>>>
>>>> Hi,
>>>>
>>>> I'm looking for a way to define a default foreign key dynamically.
>>>>
>>>> For example if I have the following schema:
>>>>
>>>> db.define_table('owner',Field('name', 'string'), 
>>>> Field('isdefault','boolean',default=False))
>>>> db.people.insert('name'='Bill')
>>>> db.people.insert('name'='unknown',isdefault=True)
>>>> db.define_table('dog', 
>>>> Field('name','string'),Field('owner',db.owner,default=????))
>>>> db.dog.insert(name='Fido',owner=1)
>>>> db.dog.insert(name='mutt') # hopefully points to "unknown" in owner 
>>>> table
>>>>
>>>> Is there a way I could dynamically check the "owner" table and return 
>>>> the id of the first row where isdefault==True whenever I define a new 
>>>> "dog" 
>>>> without an owner?
>>>> In the example above the "mutt" row should have owner==2 ("unknown" in 
>>>> the owner table).
>>>>
>>>> Trying to put a function as the default argument does not work. I 
>>>> realize I could set the owner to always be the first row in the table but 
>>>> I 
>>>> would like something more robust and flexible.
>>>>
>>>> Thanks
>>>> Vincent
>>>>
>>>>

Reply via email to