Skip to Content
Menu
This question has been flagged
6998 Views

I am trying to use the mapped() operation on a recordset in v8, as described in:

https://www.odoo.com/documentation/8.0/reference/orm.html#other-recordset-operations

I use it on a recordset of model A to retrieve all the records in a field_a, which is a Many2one,

expected_ids = recorsetA.mapped('field_a')

but it fails with this error:

  File "/mnt/workZone/odoo/odoo_8_devel/code/OCA/OCB/openerp/models.py", line 5196, in ensure_one
    raise except_orm("ValueError", "Expected singleton: %s" % self)
except_orm: ('ValueError', 'Expected singleton: res.better.zip(32506, 32503, 32505, 32504, 32502, 32508, 32507, 32509, 32510, 32512, 32511, 32513, 32514, 32515, 32516, 32527, 32526, 32525, 32524, 32523, 32522, 32521, 32520, 32519, 32518,
(...)

It works with other kind of field, like Char, Int or even Many2one (but not a Many2many or One2many), like this

result_ids = recorsetA.mapped('id')

Do I need to do anything else to retrieve a recordset with all the objects within the m2m fields of the records in my recordset?

 

Avatar
Discard
Author

As stated in https://www.odoo.com/forum/help-1/question/how-to-get-a-recordset-from-a-one2many-or-many2many-field-in-a-python-file-73965 this is solved. Mapped works like a charm, by I defined wrongly a field as One2many when I should have used Many2many.

Related Posts Replies Views Activity
0
Jan 24
378
2
May 23
6768
1
Feb 22
21397
5
Dec 21
15004
0
Dec 20
3651