[web2py] Re: ondelete=CASCADE

2016-01-27 Thread Niphlod
primary keys are primary keys. their only purpose is to be as small as 
possible while uniquely identifiyng a row, with the added bonus of being 
ordered.
if you need strict sequential ordering, use another field.

On Wednesday, January 27, 2016 at 12:49:09 PM UTC+1, Pierre wrote:
>
> Hi everyone
>
> The default behaviour will result in irregular primary-key sequence like : 
> (1,2,3,6,7,8,12,13,14,20,23...etc)
> also It seems impossible to retrograde the 'automat-id-counter' like : 
> db.table.insert(id=5,field=value) eventhough there's no record with id=5
> so is it ok to let ondelete=cascade do its job or better to update-insert 
> deletable records ?
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: ondelete cascade on id attribute

2012-05-27 Thread Anthony
You can explicitly specify the id field of a table:

Field('id', type='id', ...)

And you can even give it a different name:

Field('myid', type='id', ...)

See http://web2py.com/books/default/chapter/29/6?search=named+id+field.

But why do you want to set ondelete for an id field -- it's supposed to be 
used for reference fields?

Anthony

On Sunday, May 27, 2012 6:57:31 AM UTC-4, rahulserver wrote:
>
> How should i specify ondelete='Cascade' on the id attribute of the parent 
> table, since we do not usually specify the id attribute in web2py tables. 
>


Re: [web2py] Re: ondelete='CASCADE'

2012-03-04 Thread Jan Rozhon
Well, the problem is most likely in my (not) understanding the concept 
of cascade deletion. In my case, I try to create an interface 
application for network load tests. Each time I run a test with certain 
params I want them to be stored so the user can see them and repeat test 
whenever he wants. This is done by the "tests" table, in addition user 
should be provided with detailed analysis of message counts through 
"test_counts" table and errors through "test_errors" table (not in 
example). For each test I generate unique test_id (actually timestamp) 
which identifies test together with its results. I want to make sure, 
that when a user deletes a record of a certain test in the "tests" table 
then all the appropriate records in "test_counts" and "test_errors" get 
deleted as well. I tried it with table as you can see in my first post, 
but the "test_counts" entries remained in table although the test_id was 
referenced correctly and I am not able to modify it to be working as 
expected and described. I could actually use a autogenerated "id" but 
then it should work in the first place, shouldnt it?


Thank you, Jan

Dne 4.3.2012 21:10, Anthony napsal(a):


Thanks for your quick response, Anthony. If I got it correctly, it
would be working as expected if I changed the test_id type from
integer to id. I gave it a try, but it only raised some errors
(missing required field)


Changing "test_id" to type "id" should work, but you might need to 
start with a fresh table, as an "id" type field is an 
auto-incrementing integer field.


and more importantly, it did not allow me to insert this field
manually. Is there some other approach to reference other value
than id?


You wouldn't set the value of an id field manually. Why do you need a 
separate test_id field -- if it is unique per record, the 
automatically generated id field should work? In any case, why do you 
need test_counts.test_id to be the tests.test_id field rather than the 
tests.id field? In the latter case, you can still access the 
tests.test_id field (via a join or second query), and cascading 
deletes will work fine as well (i.e., when a record in tests is 
deleted, referencing records in test_counts will also be deleted).


Anthony



Re: [web2py] Re: ondelete='CASCADE'

2012-03-04 Thread Anthony

>
> Thanks for your quick response, Anthony. If I got it correctly, it would 
> be working as expected if I changed the test_id type from integer to id. I 
> gave it a try, but it only raised some errors (missing required field)
>

Changing "test_id" to type "id" should work, but you might need to start 
with a fresh table, as an "id" type field is an auto-incrementing integer 
field.
 

> and more importantly, it did not allow me to insert this field manually. 
> Is there some other approach to reference other value than id?
>

You wouldn't set the value of an id field manually. Why do you need a 
separate test_id field -- if it is unique per record, the automatically 
generated id field should work? In any case, why do you need 
test_counts.test_id to be the tests.test_id field rather than the tests.id 
field? In the latter case, you can still access the tests.test_id field 
(via a join or second query), and cascading deletes will work fine as well 
(i.e., when a record in tests is deleted, referencing records in 
test_counts will also be deleted).

Anthony

 

Re: [web2py] Re: ondelete='CASCADE'

2012-03-04 Thread Jan Rozhon
Thanks for your quick response, Anthony. If I got it correctly, it would 
be working as expected if I changed the test_id type from integer to id. 
I gave it a try, but it only raised some errors (missing required field) 
and more importantly, it did not allow me to insert this field manually. 
Is there some other approach to reference other value than id?


Thanks, Jan

Dne 4.3.2012 19:41, Anthony napsal(a):
Note, when you create a table with define_table, it automatically 
creates a field called "id" of type "id", which serves as the record 
ID. In your test_counts table, the test_id field is therefore 
referencing the "id" field of the tests table, not the test_id field, 
which is just a regular integer field. In any case, because of the 
ondelete='CASCADE', when you delete a record from tab.tests, it should 
delete any records from tab.test_counts that reference that record.


Anthony

On Sunday, March 4, 2012 12:42:05 PM UTC-5, Jan Rozhon wrote:

Hi all, I have a newbie question regarding the cascade delete of
referenced database entries. Basically, I have these two tables:
tab = DAL('sqlite://tab.sqlite')
tab.define_table('tests',
 Field('test_id', 'integer', required=True,
default=''),
 Field('test_pid', 'integer', ondelete='NO ACTION'),
 Field('args'))
tab.define_table('test_counts',
 Field('test_id', tab.tests,
requires=IS_IN_DB(tab, tab.tests.test_id, '%(test_id)s'),
ondelete='CASCADE'),
 Field('message'))

and I want web2py to create SQLite tables tests and test_counts.
Test_counts should reference "test_id" field from the tests table
and whenever the test entry with the corresponding test_id is
deleted the appropriate rows in test_counts should be deleted as
well, but it doesnt work that way and I am unable to find a
solution either using my knowledge or google as well.

Thanks in advance for any answer, Jan




--
Ing. Jan Rozhon
Doktorand katedry telekomunikační techniky
VŠB-TU Ostrava



[web2py] Re: ondelete='CASCADE'

2012-03-04 Thread Anthony
Note, when you create a table with define_table, it automatically creates a 
field called "id" of type "id", which serves as the record ID. In your 
test_counts table, the test_id field is therefore referencing the "id" 
field of the tests table, not the test_id field, which is just a regular 
integer field. In any case, because of the ondelete='CASCADE', when you 
delete a record from tab.tests, it should delete any records from 
tab.test_counts that reference that record.

Anthony

On Sunday, March 4, 2012 12:42:05 PM UTC-5, Jan Rozhon wrote:
>
> Hi all, I have a newbie question regarding the cascade delete of 
> referenced database entries. Basically, I have these two tables:
> tab = DAL('sqlite://tab.sqlite')
> tab.define_table('tests', 
>  Field('test_id', 'integer', required=True, default=''), 
>  Field('test_pid', 'integer', ondelete='NO ACTION'), 
>  Field('args'))
> tab.define_table('test_counts',
>  Field('test_id', tab.tests, requires=IS_IN_DB(tab, 
> tab.tests.test_id, '%(test_id)s'), ondelete='CASCADE'), 
>  Field('message'))
>
> and I want web2py to create SQLite tables tests and test_counts. 
> Test_counts should reference "test_id" field from the tests table and 
> whenever the test entry with the corresponding test_id is deleted the 
> appropriate rows in test_counts should be deleted as well, but it doesnt 
> work that way and I am unable to find a solution either using my knowledge 
> or google as well.
>
> Thanks in advance for any answer, Jan 
>