Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
21239 Lượt xem

The Documentation states that the various methods of the class openerp.osv.orm.BaseModel like browse, search, write, etc. can receive and return a single id/record.

Example: return value for browse method:

Return type: object or list of objects requested

Or select argument for browse method:

select -- id or list of ids.

Or return value for search method:

Returns: id or list of ids of records matching the criteria

I often have the feeling that this is not true and all methods allways expect and return lists.

Is my feeling wrong?

 

EDIT (in lack of comment functionality):

Thx, Mr. Reis. You are quite right! But is it also true for search?

EDIT:

Search always returns a list. The documentation is wrong. (Although the technical memento states it correctly).

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

It's actually True:

If you do `object.browse(cr, uid, id)`you get one Browse record use use dot-notations directlty on it.

If you do `object.browse(cr, uid, [ids])` you get a *list* of Browse and you should iterate on it to deal with each Browse record.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

It's a good practice to always

  • send or return a list of ids
self.write(cr, uid, [lead.id], vals, context=context)
  • expect both
if isinstance(ids, (int, long)):
    ids = [ids]

 

copy is one of the only method of the orm that expects an int instead of a list.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Yes, it is right that most of the ORM methods accepts list of IDs and some of them returns list of IDs or single ID.

Search methods returns list of IDs, write, unlink returns True and create returns new ID.

You can see all the methods here: http://bazaar.launchpad.net/~openerp/openobject-server/7.0/view/head:/openerp/osv/orm.py

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
9
thg 2 17
11248
4
thg 1 16
10418
0
thg 3 15
4918
0
thg 3 15
4806
4
thg 6 20
27054