PostgreSQL – How to create anone2one relationship in ODOO 8?

I have two sets of data showing a one-to-one relationship.

I cannot merge these two sets of data because:

> A specific record may only appear in set A, only appear in set B, or appear in both set A and set B; and the association between records in set A and set B is Temporarily, this means that records can become related and can become irrelevant; and
>The data in set A is handled differently from the data in set B; and
>There are external architectural restrictions.
> /p>

When a record in set A is associated with a record in set B, I want to link the two records. When linking records, the relationship must be one-to-one. How can I ensure that this relationship is one One-to-one relationship?

The following code seems close, but I am not familiar with using Odoo and am not sure how to analyze whether this method guarantees a one-to-one relationship.

import openerp

class A(openerp.models.Model):

_name ='set.a'

_sql_constraints = [
( 'set_b_id','unique("set_b_id")','Field set_b_id must be unique.'),
]

# Constrained to be unique (see SQL above) which essentially changes< br /> # this end of the Many2one relationship to a One2one relationship. (The
# other end of the relationship must also be constrained.)

set_b_id = openerp.fields.Many2one(< br /> comodel_name='set.b',
)

class B(openerp.models.Model):

_name ='set.b'< br />
# Constrained to tie with either zero keys or one key (see function
# below) which essentially changes this end of the One2many
# relationship to a One2one relationship. (The other end of the
# relationship must also be constrained.)

set_a_id = openerp.fields.One2many(
comod el_name='set.a',
inverse_name='set_b_id',
)

@openerp.api.constrains('set_a_id')
def _constrains_set_a_id(self ):
if len(self.set_a_id)> 1:
raise openerp.exceptions.ValidationError('Additional linkage failed.')

Another method might be to extend openerp. fields to recreate the previously deprecated One2one relationship, but I am not sure if it can be done cleanly.

In your case, basically the one-to-one relationship is not available in Odoo 8.0, it completely deprecated a version 7.0 or higher in Odoo (officially OpenERP).

So please my suggestion is, don’t use one-to-one relationship, just use it as many2one, and set your local according to your needs.

I hope my answer may be right for you Help:)

I have two sets of data showing a one-to-one relationship.

I can’t merge these two sets of data, Because:

>A specific record may only appear in set A, only in set B, or both in set A and in set B; and
>set A and set The association between the records in B is temporary, which means that the records can become related and can become irrelevant; and
>The data in set A is handled differently from the data in set B; and< br>>There are external architecture restrictions.

When the records in set A are associated with records in set B, I want to link the two records. When linking records, the relationship must be one-to-one .How can I ensure that this relationship is one-to-one?

The following code seems close, but I am not familiar with using Odoo and am not sure how to analyze whether this method guarantees a one-to-one relationship.

import openerp

class A(openerp.models.Model):

_name ='set.a'

_sql_constraints = [
( 'set_b_id','unique("set_b_id")','Field set_b_id must be unique.'),
]

# Constrained to be unique (see SQL above) which essentially changes< br /> # this end of the Many2one relationship to a One2one relationship. (The
# other end of the relationship must also be constrained.)

set_b_id = openerp.fields.Many2one(< br /> comodel_name='set.b',
)

class B(openerp.models.Model):

_name ='set.b'< br />
# Constrained to tie with either zero keys or one key (see function
# below) which essentially changes this end of the One2many
# relationship to a One2one relationship. (The other end of the
# relationship must also be constrained.)

set_a_id = openerp.fields.One2many(
comodel_ name='set.a',
inverse_name='set_b_id',
)

@openerp.api.constrains('set_a_id')
def _constrains_set_a_id(self ):
if len(self.set_a_id)> 1:
raise openerp.exceptions.ValidationError('Additional linkage failed.')

Another method might be to extend openerp. fields to recreate the previously deprecated One2one relationship, but I’m not sure if it can be done cleanly.

In your case, basically one-to-one The relationship of is not available in Odoo 8.0, it is completely deprecated in Odoo (officially OpenERP) a 7.0 or higher version.

So please my advice is, don’t use One-to-one relationship, just use it as many2one, and set your local according to your needs.

I hope my answer may be helpful to you:)

Leave a Comment

Your email address will not be published.