On 02/10/12 11:07 -0700, Valentin Hapiot wrote: > Hi just checkouted the 2.5 branch and saw that the new version will use the > active record pattern. > I'm a bit disappointed because I like simplicity, and to at first sight, > using this pattern forces those noisy decorators in the methods, it also > make things more complex by thinking about static or class methods where > you don't want to. That said, I guess there are some benefits, but I don't > get what they are. So I googled a bit in order to find more information > about this major api change but couldn't find anything except some code > reviews. > > So could someone explain what is the rationale behind this active record > migration ?
They are many benefits, here are somes: - reduce the amount of code (about 2.2k lines removed) for example on_change_with and getter of Function field can be merged. - unified access to the value of record: remove of values dictionnary on on_change method. - remove loop in getter of Function field before: def getter(self, ids, name): res = {} for record in self.browse(ids): res[record.id] = ... return res now: def getter(self, name): return self.... - rationale the register process of Model (use copy of fields etc.) - remove session in wizard - ... > Extra question: Is it possible to write a module using the 'old way' (eg: I > just want to write methods without bothering what happens behind the scene, > and model's method overloading should be natural and no-brainer) ? In some way, you can by using classmethod. Indeed the principle did not change but now it is more logical and pythonic. -- Cédric Krier B2CK SPRL Rue de Rotterdam, 4 4000 Liège Belgium Tel: +32 472 54 46 59 Email/Jabber: cedric.kr...@b2ck.com Website: http://www.b2ck.com/
pgpbyt9L88Sts.pgp
Description: PGP signature