On 23 Apr 14:34, M. Murray wrote: > I am attempting to use the UnionMixin available in 3.4 to make a model that > is just a collection of records from other models. All the other ModelSQLs > have a few common fields and these fields are defined on the model that > uses the UnionMixin. Based on my understanding, that's how the UnionMixin > determines which field to select from each of the models' tables used in > the union. > > My questions are about the recommended way to do things as it relates to > this Mixin. > > 1. Should I inherit from ModelSQL *and* UnionMixin? - I think yes > because it's ModelSQL's methods that are overridden to make UnionMixin work > 2. If the answer to #1 is yes, should I register the model in the Pool? > When I do, it creates a table for the UnionMixin model. Is this expected?
It must be registered but it is not expected. See how Union are define here: http://hg.tryton.org/trytond/file/10cfbb9153b6/trytond/tests/model.py#l75 The order of dependency is important. > 3. Looking at the code, I see that I can unshard the union-ised ID to > get the index of the original model. Is this the recommended way for me to > identify the original model? Why not. > 4. Is there a way to rewire the [New Record] button to give the user a > chance to choose which model, within the union, to create or which form to > use? If not, I think I may be able to use a wizard No, Union are readonly. > 5. Further to #4, is there a way to rewire the double-click in the tree > view so it opens the appropriate form for the model of row clicked? You probably should be able to trigger a wizard on click that will open the right form base on the active_id. > And finally, am I on the right track or did I misunderstand the purpose of > the UnionMixin? No, it seems you have a valid use case. -- Cédric Krier - B2CK SPRL Email/Jabber: [email protected] Tel: +32 472 54 46 59 Website: http://www.b2ck.com/
