تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
6382 أدوات العرض

I have a problem with a Many2many-Relation (Odoo 13). Let's assume people are spotting Nessie, which a researcher documents in a module. Many witnesses can spot nessie, and one witness can spot Nessie many times. So I have two models with a Many2many-Relation:

class Sighting(models.Model):
_name = 'nessie.sighting'
witnesses = fields.Many2many('nessie .witness', 'sighting_witness_rel', 'sighting_id', 'witness_id', string="Witnesses")

class Witness(models.Model):
_name = 'nessie.witness'
sightings = fields.Many2many('nessie .sighting', 'sighting_witness_rel', 'witness_id', 'sighting_id', string="Sightings")

When I try to install the "Nessie" module, I get the following error: "ERROR:  Relation »_unknown« doesn't exist" (from postgresql). I don't get what I'm doing wrong, syntax seems correct. Declaring Many2many only once neither doesn't help, nor would meet requiremenst if it did.

Can somebody please enlighten me? Thx!

الصورة الرمزية
إهمال
الكاتب أفضل إجابة

@rehan: Thx, I checked it, but the whitespace is an artifact of writing above post, it does not occur in the source code.

الصورة الرمزية
إهمال
الكاتب

Ok, found the reason myself: in fact, class "Witness" didn't derive directly from "models.Model", but only indirectly from Person, which derives from models.Model. This seems to break Odoos inheritance mechanism, so that when Many2many tries to update the Model's relation in the db, the Model's co_model is unknown.

Only when I derive "Witness" from "models.Model" and use "_inherit" to derive also from "Person", the Many2many relation works correctly.

This is *not* working (in fact my original code):

class Witness(Person):

_name = 'nessie.witness'

sightings = fields.Many2many('nessie .sighting', 'sighting_witness_rel', 'witness_id', 'sighting_id', string="Sightings")

This *is* working:

class Witness(models.Model):

_name = 'nessie.witness'

_inherits = 'nessie.person'

sightings = fields.Many2many('nessie .sighting', 'sighting_witness_rel', 'witness_id', 'sighting_id', string="Sightings")

أفضل إجابة

i think you have syntax eror

sightings = fields.Many2many('nessie .sighting', 'sighting_witness_rel', 'witness_id', 'sighting_id',   string="Sightings") you have space when declaring model  'nessie .sighting'

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
ديسمبر 15
5795
1
فبراير 24
2256
0
يوليو 24
3403
0
يوليو 22
60
1
يوليو 22
3268