2014-06-28 21:16 GMT+02:00 Cédric Krier <cedric.kr...@b2ck.com>:

> Hi,
>
> Sometimes, a Function field could be just written as SQL expression and
> it is a pity to have to write a getter and searcher.
> So the idea will be to have a field that will behaves like a Function
> field but you will only have to define the SQL statement.
>
> To have such feature, we will need to redesign the API of field.
> For now, field could have a get, set and convert_domain methods.
>
> The get method if defined is called to modify or compute the value.
> API: `get(self, ids, Model, name, values=None)`
>
> The set method if defined is called to set the value in create/write
> instead of being a UPDATE column.
> API: `set(self, Model, name, ids, value, *[ids, value, …])`
>
> The convert_domain is always called when searching on the field.
> API: `convert_domain(self, domain, tables, Model)`
>
> The awkward is that the 'set' method presences is used on
> `ModelSQL.read` to know if the column must be a column in `SELECT`.
>
>
> My proposal is to re-use the existing `sql_column` (from changeset
> 156f1cfee9f2) instead of 'set' method for read.
> Then we could change the API of get method: get(self, Model, name, ids)
> We will no more need of values because such case could be handle with
> sql_column.
>
> So the new field could be:
>
>     class FunctionSQL(_Function):  #common part with Function
>         def __init__(self, field, column, setter=None, loading='eager'):
>             …
>         def sql_column(self, table, Model):
>             return getattr(Model, self.column)(table)
>
>         # convert_domain should work out of the box
>         # no get
>

I think this would be a nice improvement.


-- 
Albert Cervera i Areny
Tel. 93 553 18 03
@albertnan
www.NaN-tic.com

Reply via email to