Using an One2One field

I have two separate models which have both a field that connects to the other.

class Foo():
    __name__ = ''
    bar = fields.Many2One('', 'Bar')

class Bar():
    __name__ = ''
    foo = fields.Many2One('', 'Foo')

When I fill the foo-field I want to automatically fill the bar-field. To do that I want to use an One2One relation. According the documentation and looking into the tests directory it seems to me that the behavior is the same as with a Many2Many relation. So an new table is needed for the Many2One fields and on both classes the field has to be changed.

The question is on which model to place the One2One field? Or can both models have an One2One field?

Both models can have a One2One field declared the origin and target must just be inverted.

That worked nicely! When I add a record for the second time to another record the Unique constraint spring into action.

A nice addition is to extend my domain to filter out the records which are already linked. But I think that will need a Function field to get the right id’s.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.