Bidirectional many2many fields in the GUI

Asked by larscwallin

I want to add a many2many field to connect two object types.

I did this:

1. Added the many2many field "x_contact_team_ids" to "res.partner.contact"
2. Added the many2many field "x_team_contact_ids" to "res.partner.team"
3. Set up the form-views using the relation fields above.
4. Tested the many2many relation by adding a Team to Contact. This worked fine.
5. Went over to the Team form view to see that the Contact ended up in the many2many view list there as well... Which it had not
6. So i realized that i had not specified any relation table as i would have in py code.
7. Went into the "x_contact_team_id" field and found that i had no way of specifying this relationship?

How do i do this in the IDE (the OpenObject GUI tools)?

Thanks,
Lars

Question information

Language:
English Edit question
Status:
Answered
For:
Odoo Web Client Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Vinay Rana (OpenERP) (vra-openerp) said :
#1

Hello larscwallin,

I have done the same steps at my end but i can not understand the following step that what you want to say?
5. Went over to the Team form view to see that the Contact ended up in the many2many view list there as well... Which it had not
Can you explain me more clear so i can understand , what is the problem?

Thanks.

Revision history for this message
larscwallin (larscwallin) said :
#2

Hi,
Sorry for the late reply.

When working with relations between objects the assumption is that a many 2 many relationship is bidirectional.
In other words:

If i create a m2m relationship to object1 from object2, like "object2.addObject(object1)", the change should also be reflected in object1; "object1.getObjectList()" should return object2, "object2.getObjectList()" should return object1.

The same pattern is true for all relational bindings according to common practice as we all know.

This is what i meant by point number 5. I added many2many relationship fields to both objects, added a ref to a Team object in the Contacts view. If all things went according to the m2m pattern the Team should list this contact ref in its list of Contacts. Otherwise its not a many2many binding.

In the py code, when making custom Classes, you specify :

fields.many2many(’other.object.name’,
’relation object’,
’other.object.id’,
’actual.object.id’,
’Field Name’)

This means that you have specified [Object1] -> [Rel. Table] <- [Object2]

In the Customization client you can only specify,

Field Type and Object Relation which leaves us with [Object1] -> ? <- [Object2]

So in other words, as far as i can see, many2many wont work in the customization client.

Thanks,
Lars

Revision history for this message
Vinay Rana (OpenERP) (vra-openerp) said :
#3

Hello larscwallin,

Yes that is true. In many2many relation there should be intermediate table which is not created in this case.

Thanks.

Revision history for this message
larscwallin (larscwallin) said :
#4

Ok, so should we file a new bug?

I have a new potential ODOO customer where i need both m2m and o2m, which also seems non functional, to demo a silution.
Do you have any good work arounds?

Thanks again

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) said :
#5

At the moment the GUI field editor does not allow creating many-to-many relationship.

Just an idea:
You could try to accomplish this by creating explicitly the intermediate many-to-many object (x_partner_team_rel) to implement the many-to-many table. This object would have two many2one columns pointing to the 2 endpoints (team and contact). Then you could add the opposite one2many relationships into your 2 objects, this time pointing to the intermediate object.
It will perhaps be a little bit convoluted to use the one2many widget in this way though...

Revision history for this message
Fabien (Open ERP) (fp-tinyerp) said :
#6

Hello,

You can easily develop your own type field by inherting from the
fields.one2many. I already developed this for some modules but I can't
remember which one. You don't need to change anything in the client side.

Thanks,

Olivier Dony (OpenERP) wrote:
> Question #102510 on OpenObject Web Client changed:
> https://answers.launchpad.net/openobject-client-web/+question/102510
>
> Status: Open => Answered
>
> Olivier Dony (OpenERP) proposed the following answer:
> At the moment the GUI field editor does not allow creating many-to-many
> relationship.
>
> Just an idea:
> You could try to accomplish this by creating explicitly the intermediate many-to-many object (x_partner_team_rel) to implement the many-to-many table. This object would have two many2one columns pointing to the 2 endpoints (team and contact). Then you could add the opposite one2many relationships into your 2 objects, this time pointing to the intermediate object.
> It will perhaps be a little bit convoluted to use the one2many widget in this way though...
>

--
Fabien Pinckaers
CEO Tiny - OpenERP Editor
Chaussée de Namur 40
B-1367 Grand-Rosière
Belgium
Phone: +32.81.81.37.00
Fax: +32.81.73.35.01
Web: http://openerp.com

Great Achievements Start With Tiny Investments
  -- Marty, 2005

Revision history for this message
larscwallin (larscwallin) said :
#7

Ok, thanks everybody.

How can i inherit from a field type in the editor? Dont forget that i cant code anything if i want to ODOO.

Olivers way seem pretty good i guess...

Is there anyway to use the one2many field and populate it with a query result from a table?
Or can i use the Reference field in some way?

Please stay with me until we come to some kind of solution, and i will write something on the WIKI about it.

Also, please write about this in the manuals to avoid confusion. Otherwise your new trail-version prospects will find the software buggy and instable. The general rule is always: Never create expectations which you can not exceed.

Ciao,
Lars

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) said :
#8

On 12/03/10 17:07, larscwallin wrote:
> How can i inherit from a field type in the editor? Dont forget that i
> cant code anything if i want to ODOO.

I really don't see how this could be possible for the graphical field
editor at the moment, so I'd say you can't.

> Olivers way seem pretty good i guess...

That's the only way I can see to establish some sort of many-to-many
relationship that can be edited in both directions. The problem with
this technique is of course that you will have to explicitly create the
intermediary objects whenever you want to link an object in the m2m.
This is what I was referring to in my previous post: your final
interface will be a o2m widget towards the m2m intermediate object, not
an actual m2m widget :-/

And the original issue with symmetrical m2m relationships is that the
current graphical field editor creates everything transparently for you
and doesn't allow you to select an existing opposite relationship.
So as you've experienced, you would end up with two independent m2m
relationships, each with only one endpoint available as a field.

Note: there's already a task in the R&D backlog to improve the object
editor for these kinds of cases, so it will be possible in a future
version (sorry, no ETA yet)

> Is there anyway to use the one2many field and populate it with a query result from a table?

If you mean dynamically, yes and no. Yes because it can be achieved
easily with a 'function' field or a 'related' field, and no in your case
because these field types are not available at all using the graphical
editor.

If you mean statically (just importing data once), then yes, you can use
CSV import/export or XML-RPC directly to do it.

> Or can i use the Reference field in some way?

No, reference fields are simply many2one fields that can target more
than one model.

> Please stay with me until we come to some kind of solution, and i will
> write something on the WIKI about it.

I can't see any other workaround with the current release on ODOO, but
there's a good chance this will be supported in next release.

> Also, please write about this in the manuals to avoid confusion.
> Otherwise your new trail-version prospects will find the software buggy
> and instable. The general rule is always: Never create expectations
> which you can not exceed.

If you have been mislead about ODOO's capabilities in this area, would
you mind indicating the official source?

Revision history for this message
larscwallin (larscwallin) said :
#9

Hi Oliver,

Thanks for your detailed answer! I will try out the manual reference object solution you suggested.

About the "missleading information", i have built my expectations (which of course are subjective) around the Community information. And of course around the existance of the customization features available in the product.

What i mean i simply that if you have the possibility to create custom objects and fields, and these differ in functionality aspect compared to the Community docs, you have to be clear on this point.

Currently i would say that the only stable relationship field type is many2one. one2many relationships crash between custom objects for example (reported as a bug without any response).

Now let me round up by saying that the reason that i take the time to write this is that i LOVE OpenObject. I have been following this project since 3 years back or so, and i am so happy that its taking off! All my "critisism" is aimed at one thing only and that is to make OO a better product for all of us. And i have done my best to solve the problems before hassling you ;)

I am working hard to spread the word in Sweden and i have many very cool projects coming up.

All the best,
Lars

Can you help with this problem?

Provide an answer of your own, or ask larscwallin for more information if necessary.

To post a message you must log in.