On 8/10/11 2:34 AM, Vineet Deodhar wrote:
> Hello List !
>
> This is in continuation with my earlier mail on 'propython' mailing list.
> As suggested by Paul, I am posting my dabo related queries here.
>
> Preamble to my query:-
> I am trying to use just the BizObj layer into my 'web2py' framework.
> Before putting the bizobj into actual project, I am learning 'how it works'.
> So I have created a directory with full dabo folder in it.
> I import dabo and use the bizobj& connection classes.
> Working on Win7, Intel core i3, python 2.6, MySQL 5512 (no install version),
> pyScripter IDE
>
> My Query:-
>
> Data structure:
>
> 1st table name: stat
> fields: statid, statnm
>
> 2nd table name: dist
> fields: distid, distnm, statid (foreign key)
>
> Code:
>
> /MyDir/bo.py file contains ---
>
> import dabo
>
> #create a connection object
> ci = dabo.db.dConnectInfo(Host='localhost', DbType='MySQL',
> Database='whlbel', User='root', PlainTextPassword='123')
> conn = dabo.db.dConnection(ci)
>
> #create stat bizobj
> statBizObj = dabo.biz.dAutoBizobj(conn)
> statBizObj.DataSource = 'stat'
> statBizObj.KeyField = 'statid'
> statBizObj.NonUpdateFields = ['statid']
> statBizObj.UserSQL = 'select * from stat'
> statBizObj.requery()
>
> #create dist bizobj
> distBizObj = dabo.biz.dBizobj(conn)
> distBizObj.KeyField = 'distid'
> distBizObj.ParentLinkField = 'statid'
> distBizObj.NonUpdateFields = ['distid']
> distBizObj.UserSQL = 'select distid,distnm,statid,statnm from dist join stat
> using(statid)'
> distBizObj.addChild(statBizObj)
> distBizObj.requery()
>
> ---end of file---
>
> In the python shell, I tried to change a record in tables---
>
> 1] successful example--
>>>> from myDir import bo
>>>> bo.statBizObj.seek('MyState1', fld='statnm')
>>>> bo.statBizObj.setFieldVal('statnm', 'MyState2')
>>>> bo.statBizObj.isAnyChanged()
> True
>>>> bo.statBizObj.save()
> The record gets saved in the database (verified from MySQL clc).
> (note: this table doesn't have any foreign key relationship with any other
> table)
>
> 2] Unsuccessful example--
>>>> from myDir import bo
>>>> bo.distBizObj.seek('MyDist1', fld='distnm')
>>>> bo.distBizObj.setFieldVal('distnm', 'MyDist2')
>>>> bo.distBizObj.isAnyChanged()
> False
>>>> bo.distBizObj.save()
> The record DOES NOT get saved in the database (verified from MySQL clc).
> (note: this table has foreign key relationship with 'stat' table)
>
> I am not able to find out why the case 2] is not working.
> Can anybody pl. suggest?
You need:
distBizobj.LinkField = "statid"
#distBiobj.ParentLinkField = "statid" ## not needed since it is already the
KeyField
Also, comment out UserSQL for both bizobjs. Dabo will create good SQL for this
relation automatically.
Paul
_______________________________________________
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]