只为那些简单的查询使用ORM层。有一些简单的方法,这(例如,对于典型的CRUD->创建,读取,更新,删除):
创建 - >创建(瓦尔斯)
# creates a user in db and
# returns this user as python object (RecordSet)
created_user = self.env['res.users'].create({'name': 'New User'})
浏览 - >浏览( LIST_OF_IDS)
# reads the whole database rows and
# returns python objects (RecordSet)
browsed_users = self.env['res.users'].browse([1,2])
搜索 - >搜索(域)
# search database with Odoo's domain syntax
# returns python objects if something were found
domain = [('name', '=', 'New User')]
searched_users = self.env['res.users'].search(domain)
这些例子只触及表面。查看Odoo's Developer Documentation了解更多信息。
编辑:使用ORM层有优点和缺点。但是在Odoo中,有一个非常大的优势:该层具有集成的用户访问控制。这只是一个很大的优势。
为什么不使用ORM层呢?对不起,但我没有看到用这样一个例子绕过ORM层的需要。 – CZoellner
@CZoellner其实我是Odoo的新手,我不知道你怎么能用ORM获取那些 – Ancient