[web2py] Re: web2py DAL one-to-one relation

2012-09-12 Thread martzi
Thanks to all members that shared their ideas with me: I was able to the solve my problem after setting foreign_keys attribute to on : sqlite> PRAGMA foreign_keys; 0 sqlite> PRAGMA foreign_keys = ON; sqlite> PRAGMA foreign_keys; 1 On Monday, September 10, 2012 12:45:28 PM UTC+2, martzi wrote:

[web2py] Re: web2py DAL one-to-one relation

2012-09-11 Thread Anthony
On Tuesday, September 11, 2012 3:59:45 PM UTC-4, martzi wrote: > > FYI : putting all the fields in one table will result to multiple columns > ... > I don't understand the objection -- that's the idea -- let the table have multiple columns instead of moving those columns to other tables. But I'

[web2py] Re: web2py DAL one-to-one relation

2012-09-11 Thread villas
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 som

[web2py] Re: web2py DAL one-to-one relation

2012-09-11 Thread martzi
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 "", line 1, in File "/home/martin/Documents/web2py2/gluon/dal.py", line 7234, in executesql a

[web2py] Re: web2py DAL one-to-one relation

2012-09-11 Thread martzi
FYI : putting all the fields in one table will result to multiple columns ... On Tuesday, September 11, 2012 5:31:37 PM UTC+2, Anthony wrote: > > Why do you want a one-to-one relation? Can't you just put all the fields > in one table? > > Anthony > > On Tuesday, September 11, 2012 9:23:16 AM UTC

[web2py] Re: web2py DAL one-to-one relation

2012-09-11 Thread Anthony
Why do you want a one-to-one relation? Can't you just put all the fields in one table? Anthony On Tuesday, September 11, 2012 9:23:16 AM UTC-4, martzi wrote: > > Unique = True, has probably no effect. see below. > ... > >>> db = DAL('sqlite://storage.db') > >>> person = db.define_table('person'

[web2py] Re: web2py DAL one-to-one relation

2012-09-11 Thread villas
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=Tr

[web2py] Re: web2py DAL one-to-one relation

2012-09-11 Thread martzi
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

[web2py] Re: web2py DAL one-to-one relation

2012-09-11 Thread villas
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. -

[web2py] Re: web2py DAL one-to-one relation

2012-09-11 Thread martzi
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

[web2py] Re: web2py DAL one-to-one relation

2012-09-11 Thread villas
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 con

[web2py] Re: web2py DAL one-to-one relation

2012-09-11 Thread martzi
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

[web2py] Re: web2py DAL one-to-one relation

2012-09-11 Thread villas
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 Cascad

[web2py] Re: web2py DAL one-to-one relation

2012-09-11 Thread martzi
Thanks for the reply. I have tried it, ondelete=CASCADE worked, but the referenced table seems to be accepting multiple entries ... one-to-many relation. Are there ways to prevent this from occurring ? On Monday, September 10, 2012 2:43:55 PM UTC+2, Massimo Di Pierro wrote: > > Field('','re

[web2py] Re: web2py DAL one-to-one relation

2012-09-10 Thread Massimo Di Pierro
Field('','reference other_table',ondelete='CASCADE') this is actually the default. Is this what you are asking? On Monday, 10 September 2012 05:45:28 UTC-5, martzi wrote: > > Hi, > I wonder if there a way to enforce a one to one relationship with Cascade > via web2py DAL API. ??? > --