I have the following error when I make this request:
*https://localhost/example/api/rest/PERSONS_has_ANIMALS*
*
*
type 'exceptions.AttributeError'> 'Table' object has no attribute '_id'
Versionweb2py™Version 2.5.1-stable+timestamp.2013.06.06.15.39.19PythonPython 
2.7.3: /usr/bin/python (prefix: /usr)Traceback

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.

Traceback (most recent call last):
  File "/home/www-data/web2py/gluon/restricted.py", line 212, in restricted
    exec ccode in environment
  File "/home/www-data/web2py/applications/example/controllers/api.py" 
<https://genesys-w2p-test.sistemasgenomicos.com/admin/default/edit/example/controllers/api.py>,
 line 54, in <module>
  File "/home/www-data/web2py/gluon/globals.py", line 194, in <lambda>
    self._caller = lambda f: f()
  File "/home/www-data/web2py/gluon/globals.py", line 158, in f
    return rest_action(*_self.args, **_self.vars)
  File "/home/www-data/web2py/applications/example/controllers/api.py" 
<https://genesys-w2p-test.sistemasgenomicos.com/admin/default/edit/example/controllers/api.py>,
 line 25, in GET
    parser = db.parse_as_rest(patterns,args,vars)
  File "/home/www-data/web2py/gluon/dal.py", line 7710, in parse_as_rest
    dbset=dbset(db[table])
  File "/home/www-data/web2py/gluon/dal.py", line 9809, in __call__
    query = self.db._adapter.id_query(query)
  File "/home/www-data/web2py/gluon/dal.py", line 676, in id_query
    return table._id != None
  File "/home/www-data/web2py/gluon/dal.py", line 8414, in __getitem__
    return ogetattr(self, str(key))
AttributeError: 'Table' object has no attribute '_id' *(**I do not want to 
create an additional id database.)*


*The problem is that PERSONS_has_ANIMALS table has a composite primary key. 
I made a deep search the web but can not find solution. Any idea?*
The rest web service work perfectly because the tables have only one 
primary key.

I created the following acenario to test Web2py freamework:

*MYSQL Data BASE*

<https://lh5.googleusercontent.com/-ELIoEmtIZDA/UfYtNDX-iYI/AAAAAAAAAlY/cY2t4wmhtKw/s1600/Selection_005.png>

*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*DAL MODEL*

*db.py*
db = DAL('mysql://usr:pass@localhost/db',pool_size=1,check_reserved=['all'])

*db_exampl.py*

db.define_table('ANIMALS',
    Field('idAnimal','integer'),
    Field('kind','string'),
    primarykey=['idAnimal'],
    migrate=False)

#--------
db.define_table('NUMBERS',
    Field('idNumber','integer'),
    Field('number','string'),
    primarykey=['idNumber'],
    migrate=False)

#--------
db.define_table('PERSONS',
    Field('idPerson','integer'),
    Field('name','string'),
    Field('email','string'),
    Field('idNumber','integer','reference db.NUMBERS.idNumber'),
    primarykey=['idPerson'],
    migrate=False)

#--------
db.define_table('PERSONS_has_ANIMALS',
    Field('idPerson','integer','reference db.PERSONS.idPerson'),
    Field('idAnimal','integer','reference db.ANIMALS.idAnimal'),
    primarykey=['idPerson', 'idAnimal'],
    migrate=False)


*RESTFull CONTROLLER*

*rest.py*
@request.restful()
def rest():
    response.view = 'generic.'+request.extension
    def GET(*args,**vars):
        patterns = [
            "/PERSONS[PERSONS]",
            "/PERSONS/idPerson/{PERSONS.idPerson}",
            "PERSONS/{PERSONS.name.startswith}",
            "PERSONS/idNumber/{PERSONS.idNumber}",
            
            "/ANIMALS[ANIMALS]",
            "/ANIMALS/idAnimal/{ANIMALS.idAnimal}",
            "/ANIMALS/{ANIMALS.kind.startswith}",
            
            "/NUMBERS[NUMBERS]",
            "/NUMBERS/idNumber/{NUMBERS.idNumber}",
            "/NUMBERS/{NUMBERS.name.startswith}",
            
            "/PERSONS_has_ANIMALS[PERSONS_has_ANIMALS]",
            "/PERSONS_has_ANIMALS/idPerson/{PERSONS_has_ANIMALS.idPerson}",
            "/PERSONS_has_ANIMALS/idAnimal/{PERSONS_has_ANIMALS.idAnimal}",
            ]
        parser = db.parse_as_rest(patterns,args,vars)
        if parser.status == 200:
            return dict(content=parser.response)
        else:
            raise HTTP(parser.status,parser.error)
    def POST(table_name,**vars):
        if table_name == 'PERSONS':
            return db.PERSONS.validate_and_insert(**vars)
        elif table_name == 'ANIMALS':
            return db.ANIMALS.validate_and_insert(**vars)
        else:
            raise HTTP(400)
    return locals()


-- 

--- 
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to