Re: [web2py] referenced auth.user_id type string

2011-12-16 Thread thodoris
Thanks for your answers guys. I have another question related to this topic.

Say i want to reference an authorized user instead of a person table:

db.define_table('cat', 
Field('name'),
Field('owner', db.auth_user, 
default=auth.user_id,readable=False,writable=False),) 

So that the owner of the cat is the logged in user.
Also i have a view that displays the cat owner.

Lets say i want to have the option to either keep the cat or purge it or 
five it to another owner (in general take an action), after the user has 
been deleted. How can i do it?
If i use ondelete=CASCADE the cat will be deleted
ondelete=SET NULL the owner of the cat will be NULL
ondelete=NO ACTION 

but there is no way to define take an action. Any ideas??


Re: [web2py] referenced auth.user_id type string

2011-12-16 Thread Anthony
On Friday, December 16, 2011 6:31:11 AM UTC-5, thodoris wrote:

 Thanks for your answers guys. I have another question related to this 
 topic.

 Say i want to reference an authorized user instead of a person table:

 db.define_table('cat', 
 Field('name'),
 Field('owner', db.auth_user, 
 default=auth.user_id,readable=False,writable=False),) 

 So that the owner of the cat is the logged in user.
 Also i have a view that displays the cat owner.

 Lets say i want to have the option to either keep the cat or purge it or 
 five it to another owner (in general take an action), after the user has 
 been deleted. How can i do it?
 If i use ondelete=CASCADE the cat will be deleted
 ondelete=SET NULL the owner of the cat will be NULL
 ondelete=NO ACTION 

 but there is no way to define take an action. Any ideas??


I doubt there is a way to do that with a database constraint. You'll 
probably have to handle it in your application logic.
 


Re: [web2py] referenced auth.user_id type string

2011-12-16 Thread thodoris
What do you mean handle it in application logic? How/when do i detect from 
my app that a user has been deleted?


Re: [web2py] referenced auth.user_id type string

2011-12-16 Thread Anthony
On Friday, December 16, 2011 11:01:37 AM UTC-5, thodoris wrote:

 What do you mean handle it in application logic? How/when do i detect from 
 my app that a user has been deleted?


Presumably you have code that deletes users (perhaps via an update form 
with the delete option available, or some other means). Wherever that 
happens, add the necessary code to do what you want upon deletion.

Anthony


Re: [web2py] referenced auth.user_id type string

2011-12-15 Thread thodoris
This is a solution but look at the following, if i declare


db.define_table('person', 
Field('name'),) 

db.define_table('cat', 
Field('name'), 
Field('owner',integer,db.person,default=db.person.id)) 
db.cat.owner.requires = IS_IN_DB(db, db.person.id) 
the reference is broken. Is there another solution?


Re: [web2py] referenced auth.user_id type string

2011-12-15 Thread thodoris
By reference is broken i mean that if i remove at some point the person, 
the cat that belongs to that person is not removed...


Re: [web2py] referenced auth.user_id type string

2011-12-15 Thread Anthony
On Thursday, December 15, 2011 11:42:42 AM UTC-5, thodoris wrote:

 This is a solution but look at the following, if i declare


 db.define_table('person', 
 Field('name'),) 

 db.define_table('cat', 
 Field('name'), 
 Field('owner',integer,db.person,default=db.person.id)) 
 db.cat.owner.requires = IS_IN_DB(db, db.person.id) 
 the reference is broken. Is there another solution?


If you want 'owner' to reference the 'person' table, then make it a 
'reference' field type, not 'integer':

Field('owner', db.person)

or

Field('owner', 'reference person')

Note, you can't set the default to db.person.id because that refers to the 
'id' field of the 'person' table, not a specific value for a given person.

Anthony 


Re: [web2py] referenced auth.user_id type string

2011-12-15 Thread Nik Go
Hmm.. I've actually declared fields of type 'integer', then declare a
validator  field much later in the code. Often in a custom auth_user fields
that needs to refer to tables which will be defined much later. Kinda makes
it like a pseudo-reference field.

Field('account_status', 'integer')# custom auth_user field

db.define('some_table', Field('name'))
db.auth_user.account_status.requires=IS_IN_DB(db, 'some_table.id', '%name')

Hmm.. come to think of it maybe this is possible...
db.auth_user.account_status.type='reference some_table'


On Friday, December 16, 2011, Anthony wrote:

 On Thursday, December 15, 2011 11:42:42 AM UTC-5, thodoris wrote:

 This is a solution but look at the following, if i declare


 db.define_table('person',
 Field('name'),)

 db.define_table('cat',
 Field('name'),
 Field('owner',integer,db.**person,default=db.person.id))
 db.cat.owner.requires = IS_IN_DB(db, db.person.id)
 the reference is broken. Is there another solution?


 If you want 'owner' to reference the 'person' table, then make it a
 'reference' field type, not 'integer':

 Field('owner', db.person)

 or

 Field('owner', 'reference person')

 Note, you can't set the default to db.person.id because that refers to
 the 'id' field of the 'person' table, not a specific value for a given
 person.

 Anthony



[web2py] referenced auth.user_id type string

2011-11-29 Thread thodoris
Hello,

Simple question:

auth.user.id returns an integer

but if i define a field in a table:

Field('author_id', default=auth.user_id)

author_id is a string

and if i want in a later step to compare these values it doesn't seem
good tactic to do str(auth.user.id)


Re: [web2py] referenced auth.user_id type string

2011-11-29 Thread Bruno Rocha
Field('user_id', 'integer', default=auth.user_id)
or

Field('user_id', 'reference auth_user', default=auth.user_id)

http://zerp.ly/rochacbruno
Em 29/11/2011 09:23, thodoris pasxi...@gmail.com escreveu:

 Hello,

 Simple question:

 auth.user.id returns an integer

 but if i define a field in a table:

 Field('author_id', default=auth.user_id)

 author_id is a string

 and if i want in a later step to compare these values it doesn't seem
 good tactic to do str(auth.user.id)