On Tuesday, June 28, 2011 02:14:18 pm Paul McNett wrote: > On 6/28/11 1:53 PM, John Fabiani wrote: > > On Tuesday, June 28, 2011 01:19:27 pm Paul McNett wrote: > >> > My dApp subclass handles getting the connection, and saves it to an > >> > attribute of the App 'dbConnection'. Then when I instantiate a > >> > bizobj it is just 'self.bizOrders = > >> > Orders(self.Application.dbConnection)'. > > > > How does this help? > > Nate was asking how to get the connection object from which to instantiate > the child bizobj. I told him how I do it. I certainly hope it helps! > > > You have a subclass of dApp (unless you meant an instance of dApp). > > I have a subclass of dApp, that when instantiated sets the dbConnection > attribute. > > > You have a global. > > Define "global". Not sure of the relevance... > > > If you just used the MainForm.createBizobj() wouldn't you have almost the > > same thing? > > The only difference being that the form creates the parent bizobj, but the > children are created by instantiating the parent bizobj. So instead of: > > class MyForm(dForm): > def createBizobjs(self): > parent = self.addBizobj(BizParent(connection)) > child1 = parent.addChild(BizChild1(connection)) > child2 = parent.addChild(BizChild2(connection)) > grandchild_of_child1 = child1.addChild(...) > ... > > You define the children in the bizobjs themselves, so that whenever you > instantiate a given bizobj you already have the child relationships in > place. The form just knows about whatever "parent" bizobj to instantiate > so the above becomes: > > class MyForm(dForm): > def createBizobjs(self): > self.addBizobj(BizParent(connection)) > > The end result is of course the same, you just encapsulate the code better > IMO. > > Paul
By global I mean that the connect instance is available everywhere from anywhere. The way you are using it. Where as if the connection was created in createBizobj it is only used in the MainForm method. Of course self.Application is still available to retrieve the connection. I like the flexibility of the first method where I can create generic bizobj's classes and use them differently by attaching children as required by each form. IOW's one form might require a different set of children from another form. The relationships between a parent and different children may not be static or not required for form. In Nate's case, it appears to be a straight forward parent child. In my case an enrollment has different relationships. I guess I could setup a permanent relationship but of course then I'd have the over head of the opening tables not needed. Johnf _______________________________________________ Post Messages to: [email protected] Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users Searchable Archives: http://leafe.com/archives/search/dabo-users This message: http://leafe.com/archives/byMID/[email protected]
