Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Does recordset mapped() operation work with m2m fields?

By
Alejandro Santana
on 1/22/15, 2:48 PM 1,755 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?

 

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.

Anubía, soluciones en la nube, S.L., Alejandro Santana
on 1/26/15, 1:58 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 1/22/15, 2:48 PM
Seen: 1755 times
Last updated: 5/26/15, 1:42 PM