← Back to team overview

c2c-oerpscenario team mailing list archive

[Bug 818189] [NEW] tuple (5) to unlink all values in a many2many field doesn't work

 

Public bug reported:

According to the doc : http://doc.openerp.com/v6.0/developer/2_5_Objects_Fields_Methods/methods.html#osv.osv.osv.write
There is a command to unlink all targets of a m2m field :
(5)                    unlink all (like using (3,ID) for all linked records)

According to openobject-server.6.0/bin/osv/fields.py:626 :

elif act[0] == 5:
                cr.execute('update '+self._rel+' set '+self._id2+'=null where '+self._id2+'=%s', (id,))

This code leads to the following request :

update my_own_m2m_relation_table set target_id=null where target_id=43

This request is not correct, it leads to an UPDATE 0 each time. It should be :
update my_own_m2m_relation_table set target_id=null where source_id=43
So the correct code could be :

                cr.execute('update '+self._rel+' set '+self._id2+'=null
where '+self._id1+'=%s', (id,))

But this is still false !
In the case of a many2many field, we have a separate table dedicated to linking the target values to the source field. So the correct request should be:

delete from my_own_m2m_relation_table where source_id=43

Thus the correct code should be something like:
                cr.execute('update '+self._rel+' set '+self._id2+'=null where '+self._id1+'=%s', (id,))

** Affects: openobject-server
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of C2C
OERPScenario, which is subscribed to the OpenERP Project Group.
https://bugs.launchpad.net/bugs/818189

Title:
  tuple (5) to unlink all values in a many2many field doesn't work

Status in OpenERP Server:
  New

Bug description:
  According to the doc : http://doc.openerp.com/v6.0/developer/2_5_Objects_Fields_Methods/methods.html#osv.osv.osv.write
  There is a command to unlink all targets of a m2m field :
  (5)                    unlink all (like using (3,ID) for all linked records)

  According to openobject-server.6.0/bin/osv/fields.py:626 :

  elif act[0] == 5:
                  cr.execute('update '+self._rel+' set '+self._id2+'=null where '+self._id2+'=%s', (id,))

  This code leads to the following request :

  update my_own_m2m_relation_table set target_id=null where target_id=43

  This request is not correct, it leads to an UPDATE 0 each time. It should be :
  update my_own_m2m_relation_table set target_id=null where source_id=43
  So the correct code could be :

                  cr.execute('update '+self._rel+' set
  '+self._id2+'=null where '+self._id1+'=%s', (id,))

  But this is still false !
  In the case of a many2many field, we have a separate table dedicated to linking the target values to the source field. So the correct request should be:

  delete from my_own_m2m_relation_table where source_id=43

  Thus the correct code should be something like:
                  cr.execute('update '+self._rel+' set '+self._id2+'=null where '+self._id1+'=%s', (id,))

To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-server/+bug/818189/+subscriptions


Follow ups

References