Well it seems the test worked - I guess that's what happens when the DB 
enforces 'unique'.  You'd have to put that in a try except or something.
 
Anthony suggested putting all the fields in one table.  That's what you 
would usually do with a 1-1 relationship.  Are you sure you cannot rename 
some of the fields.  You could use aliases.

However,  I also still think that the unique=True should either work or be 
documented that it doesn't.  I've added a comment to this open issue,  
which was also about 'unique'.

Issue 648 <http://code.google.com/p/web2py/issues/detail?id=648>: Unique 
fields break table inclusion (inheritance)



On Tuesday, September 11, 2012 9:01:35 PM UTC+1, martzi wrote:
>
> Thanks for the reply. But db.executesql('create unique index idx_owner on 
> bodypart(owner)') returned the below error, and still didn't solve the 
> problem.
> Traceback (most recent call last):
>   File "<console>", line 1, in <module>
>   File "/home/martin/Documents/web2py2/gluon/dal.py", line 7234, in 
> executesql
>     adapter.execute(query)
>   File "/home/martin/Documents/web2py2/gluon/dal.py", line 1659, in execute
>     return self.log_execute(*a, **b)
>   File "/home/martin/Documents/web2py2/gluon/dal.py", line 1653, in 
> log_execute
>     ret = self.cursor.execute(*a, **b)
> IntegrityError: indexed columns are not unique
>
> On Tuesday, September 11, 2012 5:17:54 PM UTC+2, villas wrote:
>>
>> Add this line as a test:
>>
>> db.executesql('create unique index idx_owner on bodypart(owner)')
>>
>> to your code like this:
>>
>> db = DAL('sqlite://storage.db')
>> person = db.define_table('person', Field('name'))
>> bodypart = db.define_table('bodypart', Field('name'), Field('owner', 
>> 'reference 
>> person', unique=True)) 
>> db.executesql('create unique index idx_owner on bodypart(owner)')
>> pid = person.insert(name='Sid')
>> bpid = bodypart.insert(name='arms', owner= pid) 
>> bodypart(bpid).owner 
>> bpid = bodypart.insert(name='mouth', owner= pid) 
>> bodypart(bpid).owner 
>>
>>
>>

-- 



Reply via email to