I don't get you, could give an InteractiveConsole example, to illustrate 
your idea.

On Tuesday, September 11, 2012 3:39:53 PM UTC+2, villas wrote:
>
> I think it does have some effect.  
> I suspect that your existing data may not be unique.  
> See whether the following helps:
>
>    - If using commandline,  try with db.commit() after.
>    - Try with a new table.
>    - Look in databases/sql.log and see whether the field was created with 
>    UNIQUE.
>    - Use a DB management tool to inspect your DB.
>
>
>
> On Tuesday, September 11, 2012 2:23:16 PM UTC+1, martzi wrote:
>>
>> Unique = True,  has probably no effect. see below.
>> ...
>> >>> 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)) #unique= True seems to have no effect
>> >>> pid = person.insert(name='Sid')
>> >>> bpid = bodypart.insert(name='arms', owner= pid) #pid = 1
>> >>> bodypart(bpid).owner #bpid = 1, first insertion of owner as 1
>> 1
>> >>> bpid = bodypart.insert(name='mouth', owner= pid) # multiple entries 
>> not caught, pid is still 1
>> >>> bodypart(bpid).owner #bpid = 2, second insertion of owner as 1 AGAIN
>> 1
>>
>> On Tuesday, September 11, 2012 2:22:09 PM UTC+2, villas wrote:
>>>
>>> I am quite familiar with cascade;  I just couldn't figure out how it 
>>> could assist you.
>>>
>>> In my opinion,  Field('....','reference other_table', unique=True)  
>>> should be supported and work.  Maybe you added the constraint later and the 
>>> DB didn't accept it because you already had duplicated field contents.
>>>
>>> In any case,  even if unique=True is not working for the moment,  then a 
>>> work-around would be to make a unique index on the field yourself.  You'll 
>>> have to handle exceptions when the insert/update fails due to duplicate 
>>> keys.
>>>
>>>
>>>
>>>
>>> On Tuesday, September 11, 2012 12:48:49 PM UTC+1, martzi wrote:
>>>>
>>>> Thanks for the reply. But if you meant Field('....','reference 
>>>> other_table', unique=True), I have tried that with failure, i am still 
>>>> having a one-to-many relation. FYI: Regarding CASCADE, an  ondelete 
>>>> cascade 
>>>> causes deletion of all referred data.
>>>>
>>>> On Tuesday, September 11, 2012 1:37:59 PM UTC+2, villas wrote:
>>>>>
>>>>> I may be wrong,  but I do not think Cascade could assist you with 
>>>>> enforcing a 1-1 relationship. 
>>>>> Maybe making the foreign key field unique would help?
>>>>>
>>>>>
>>>>> On Monday, September 10, 2012 11:45:28 AM UTC+1, martzi wrote:
>>>>>>
>>>>>> Hi,
>>>>>> I wonder if there a way to enforce a one to one relationship with 
>>>>>> Cascade via web2py  DAL API. ???
>>>>>>
>>>>>

-- 



Reply via email to