[REM] orm: m2m._no_foreign_keys attribute removed, replaced by SQL check

bzr revid: odo@openerp.com-20110923162929-nhl32ie6zc6uuj8h
This commit is contained in:
Olivier Dony
2011-09-23 18:29:29 +02:00
parent 32b50ddca0
commit f2f3c916c9
2 changed files with 9 additions and 10 deletions
+1 -8
View File
@@ -497,13 +497,7 @@ class many2many(_column):
_classic_write = False
_prefetch = False
_type = 'many2many'
def __init__(self, obj, rel, id1, id2, string='unknown', limit=None, no_foreign_keys=False, **args):
"""
:param no_foreign_keys: specifies if the relation table should not have
foreign keys constaints on ``id1`` and ``id2``. This option is
useful for many2many relationships involving views instead of
regular tables.
"""
def __init__(self, obj, rel, id1, id2, string='unknown', limit=None, **args):
_column.__init__(self, string=string, **args)
self._obj = obj
if '.' in rel:
@@ -513,7 +507,6 @@ class many2many(_column):
self._id1 = id1
self._id2 = id2
self._limit = limit
self._no_foreign_keys = no_foreign_keys
def get(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None):
if not context:
+8 -2
View File
@@ -2895,9 +2895,15 @@ class BaseModel(object):
raise except_orm('Programming Error', ('There is no reference available for %s') % (f._obj,))
ref = self.pool.get(f._obj)._table
cr.execute('CREATE TABLE "%s" ("%s" INTEGER NOT NULL, "%s" INTEGER NOT NULL, UNIQUE("%s","%s")) WITH OIDS' % (f._rel, f._id1, f._id2, f._id1, f._id2))
if not f._no_foreign_keys:
self._foreign_keys.append((f._rel, f._id1, self._table, 'CASCADE'))
# create foreign key references with ondelete=cascade, unless the targets are SQL views
cr.execute("SELECT relkind FROM pg_class WHERE relkind IN ('v') AND relname=%s", (ref,))
if not cr.fetchall():
self._foreign_keys.append((f._rel, f._id2, ref, 'CASCADE'))
cr.execute("SELECT relkind FROM pg_class WHERE relkind IN ('v') AND relname=%s", (self._table,))
if not cr.fetchall():
self._foreign_keys.append((f._rel, f._id1, self._table, 'CASCADE'))
cr.execute('CREATE INDEX "%s_%s_index" ON "%s" ("%s")' % (f._rel, f._id1, f._rel, f._id1))
cr.execute('CREATE INDEX "%s_%s_index" ON "%s" ("%s")' % (f._rel, f._id2, f._rel, f._id2))
cr.execute("COMMENT ON TABLE \"%s\" IS 'RELATION BETWEEN %s AND %s'" % (f._rel, self._table, ref))