It is currently Wed May 23, 2012 2:45 pm

All times are UTC + 2 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: [Solved] many2many fields : question
PostPosted: Wed Jul 20, 2011 11:23 am 
Offline

Joined: Mon May 16, 2011 4:20 pm
Posts: 27
Hello everybody,

I am developing in an OpenERP module and I have to develop a many2many field.

I know the syntax :

Code:
fields.many2many('other.object.name',
                                          'relation object',
                                          'actual.object.id',
                                          'other.object.id',
                                          'Field Name')


But I don't understand the 2 id that we have to put 'actual.object.id' and 'other.object.id'.

How can we know which id to choose ?

Thanks by advance.

Regards.


Last edited by kilrou on Thu Jul 21, 2011 12:22 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: many2many fields : question
PostPosted: Wed Jul 20, 2011 12:25 pm 
Offline

Joined: Thu Mar 31, 2011 8:45 am
Posts: 242
Location: Málaga, Spain
I don't know if i understand your question or not, just think about the many2many creates a table in the DB with the name 'relation object' and 2 columns, one will be named 'actual.object.id' which openerp will store the id of the current object there and the other column 'other.object.id' which will store the id of the related object there.

Yo can name them as you want, for example:
Code:
class addonname_objectA(osv.osv):
...
   _columns = {
      'relation_A2B_id':fields.many2many('addonname.objectB','rel_table_name','rel_id_a','rel_id_b','Some name here'),


In this case, objectB should be declared before this relation, and so if you want to relate B with A, you should extend the objectB after objectA and inverte the relation
Code:
class addonname_objectB_ext(osv.osv):
...
    _inherit = "addonname.objectB"
   _columns = {
      'relation_B2A_id':fields.many2many('addonname.objectA','rel_table_name','rel_id_b','rel_id_a','Some name here'),

_________________
Desarrollo Compuservice
Parque Tecnológico de Andalucía


Top
 Profile  
 
 Post subject: Re: many2many fields : question
PostPosted: Thu Jul 21, 2011 12:19 am 
Offline

Joined: Mon May 16, 2011 4:20 pm
Posts: 27
Thanks for your answer, but one thing I don't really understand : if we give the name we want, how can we know that we are talking about an id ? Is it predefined that in this place (in bold) :

'relation_B2A_id':fields.many2many('addonname.objectA','rel_table_name','rel_id_b','rel_id_a','Some name here')

we are talking about id and my chosen name will receive an id ?

Cause I can name this variable as I want so how can we know that they receive an id?

Thanks by advance.

Regards.


Top
 Profile  
 
 Post subject: Re: many2many fields : question
PostPosted: Thu Jul 21, 2011 9:16 am 
Offline

Joined: Thu Mar 31, 2011 8:45 am
Posts: 242
Location: Málaga, Spain
Every object (class) you define in OpenERP has usually an id field , even if you don't create that field, son the relation many2many uses those id's of both objects to link them in an intermediate table 'rel_table_name' and put them in order 'current_object_id', 'other_object_id', so those names are the name the columns will recieve in the database to store the values.

_________________
Desarrollo Compuservice
Parque Tecnológico de Andalucía


Top
 Profile  
 
 Post subject: Re: many2many fields : question
PostPosted: Thu Jul 21, 2011 10:04 am 
Offline

Joined: Mon May 16, 2011 4:20 pm
Posts: 27
ok, so it's predefined that these two arguments (whatever the name I give to them) will receive ids ?

Thanks by advance.

Regards.


Top
 Profile  
 
 Post subject: Re: many2many fields : question
PostPosted: Thu Jul 21, 2011 10:10 am 
Offline

Joined: Thu Mar 31, 2011 8:45 am
Posts: 242
Location: Málaga, Spain
That's it, that's why you can name those arguments as you want, but consider to use a name which represents the object id which is storing.

_________________
Desarrollo Compuservice
Parque Tecnológico de Andalucía


Top
 Profile  
 
 Post subject: Re: many2many fields : question
PostPosted: Thu Jul 21, 2011 11:27 am 
Offline

Joined: Mon May 16, 2011 4:20 pm
Posts: 27
Thanks a lot, it's clear.

Regards.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 2 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:

Protected by Anti-Spam ACP