On Monday, August 15, 2016 at 7:03:37 AM UTC-4, Oasis Agano wrote:
>
>
> Im also the one who posted it on stackoverflow  but still getting an error
>
> db = DAL(lazy_tables=True)
> db.define_table('employee',
>                 Field('fullname','string',label='Name'),
>                 Field('email','string'),
>                 Field('phone','string'),
>                 Field('kids', 'string'),
>                 Field('phone', 'string'),
>                 #Field('date','datetime'),
>                 Field('dob', 'datetime', label='Date'),
>                 Field('department', 'reference department',
>                       IS_IN_DB(db, 'department.id', '%(department_name)s')),
>                 auth.signature,
>                 format='%(fullname)s'
>
>                 )
> db = DAL(lazy_tables=True)
> db.define_table('department',
>                 Field('department_name', 'string', label='Department Name'),
>                 # Field('department_name', 'string', label='Department Name'),
>                 Field('manager', 'reference employee',
>                       IS_IN_DB(db, db.employee.id, '%(fullname)s')),
>                 auth.signature,
>                 format='%(department_name)s'
>                 )
>
>
> the error is AttributeError: 'DAL' object has no attribute 'employee' 
>
>
You are defining the db object twice. It is a completely new object the 
second time, so the db.employee table no longer exists at the time you 
define the db.department table. Delete that second db = DAL() line.

Also, I don't know if the above is your exact code, but it should be: 
requires=IS_IN_DB(...).

Anthony
 

> On Sunday, August 14, 2016 at 11:02:56 PM UTC+2, Oasis Agano wrote:
>
> My code is the following im trying to assign a department to employees and 
>> also create a manager in a department table
>>
>> db = DAL(lazy_tables=True)
>> db.define_table('employee',
>>             Field('fullname','string',label='Name'),
>>             Field('email','string'),
>>             Field('phone','string'),
>>             Field('kids', 'string'),
>>             Field('phone', 'string'),
>>             #Field('date','datetime'),
>>             Field('dob', 'datetime', label='Date'),
>>             Field('department', 'reference department',
>>                   requires=IS_IN_DB(db, db.department.id, 
>> '%(department_name)s')),
>>             auth.signature,
>>             format='%(fullname)s'
>>
>>             )
>> db = DAL(lazy_tables=True)
>> db.define_table('department',
>>             Field('department_name', 'string', label='Department Name'),
>>             # Field('department_name', 'string', label='Department Name'),
>>             Field('manager', 'reference employee', required='true',
>>                   requires=IS_IN_DB(db, db.employee.id, '%(fullname)s')),
>>             auth.signature,
>>             format='%(department_name)s'
>>             )
>>
>>

-- 
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.

Reply via email to