About M2M

11 views
Skip to first unread message

Cédric Krier

unread,
Feb 19, 2009, 6:15:13 AM2/19/09
to tryton
Hi,

During the refactoring process, I find an issue that will make Tryton
multi-database more difficult. It is the fields Many2Many.
Currently, you must give in parameters of the M2M field the name of the
table to use. Because of this, we must use SQL queries in this field which
is not good for multi-database.

So, I propose to change the M2M field to use a model name in parameters
instead of a table name like that we could use the model to make the SQL
queries. And with this change, we will win more the access rules, the
record rules and the history logs.
But we will have some extra code to write to define the new models.

What do you think about that?

--
Cédric Krier

B2CK SPRL
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59
Email: cedric...@b2ck.com
Jabber: cedric...@b2ck.com
Website: http://www.b2ck.com/

Udono

unread,
Feb 19, 2009, 7:36:56 AM2/19/09
to try...@googlegroups.com
Hi,

Great idea! even for a more clear modules API.


Timitos

unread,
Feb 19, 2009, 11:10:05 AM2/19/09
to Tryton
Sound good for me, too.

Carlos Perelló Marín

unread,
Feb 19, 2009, 11:19:02 AM2/19/09
to try...@googlegroups.com
Go, go, go!!!

multi database backend, there we go!!

El jue, 19-02-2009 a las 12:15 +0100, Cédric Krier escribió:
> Hi,
>
> During the refactoring process, I find an issue that will make Tryton
> multi-database more difficult. It is the fields Many2Many.
> Currently, you must give in parameters of the M2M field the name of the
> table to use. Because of this, we must use SQL queries in this field which
> is not good for multi-database.
>
> So, I propose to change the M2M field to use a model name in parameters
> instead of a table name like that we could use the model to make the SQL
> queries. And with this change, we will win more the access rules, the
> record rules and the history logs.
> But we will have some extra code to write to define the new models.
>
> What do you think about that?

--
Carlos Perelló Marín
[P+] SERVICIOS PROFESIONALES
http://www.pemas.es
mailto:car...@pemas.es || mailto:car...@gnome.org

Cédric Krier

unread,
Mar 5, 2009, 9:03:29 AM3/5/09
to tryton
On 19/02/09 12:15 +0100, Cédric Krier wrote:
> Hi,
>
> During the refactoring process, I find an issue that will make Tryton
> multi-database more difficult. It is the fields Many2Many.
> Currently, you must give in parameters of the M2M field the name of the
> table to use. Because of this, we must use SQL queries in this field which
> is not good for multi-database.
>
> So, I propose to change the M2M field to use a model name in parameters
> instead of a table name like that we could use the model to make the SQL
> queries. And with this change, we will win more the access rules, the
> record rules and the history logs.
> But we will have some extra code to write to define the new models.
>


I pushed the change.
I used this naming convention for relation Model:

class PurchaseInvoice(ModelSQL):
'Purchase - Invoice'
_name = 'purchase.purchase-account.invoice'
_table = 'purchase_invoices_rel'
purchase = fields.Many2One('purchase.purchase', 'Purchase',
ondelete='CASCADE', select=1, required=True)
invoice = fields.Many2One('account.invoice', 'Invoice',
ondelete='RESTRICT', select=1, required=True)

PurchaseInvoice()


And for specific relations:

class PuchaseIgnoredInvoice(ModelSQL):
'Purchase - Ignored Invoice'
_name = 'purchase.purchase-ignored-account.invoice'
_table = 'purchase_invoice_ignored_rel'
purchase = fields.Many2One('purchase.purchase', 'Purchase',
ondelete='CASCADE', select=1, required=True)
invoice = fields.Many2One('account.invoice', 'Invoice',
ondelete='RESTRICT', select=1, required=True)

PuchaseIgnoredInvoice()


And the Many2Many looks like:

invoices = fields.Many2Many('purchase.purchase-account.invoice',
'purchase', 'invoice', 'Invoices', readonly=True)
invoices_ignored = fields.Many2Many(
'purchase.purchase-ignored-account.invoice',
'purchase', 'invoice', 'Ignored Invoices', readonly=True)


As you see, I keep the old table name for now. We must still write the
migration code for each Model.


So now, we have no more SQL query in fields, we can historize the
Many2Many fields and we can add constraints or rules on the relation Model.

Reply all
Reply to author
Forward
0 new messages