On Thursday, August 11, 2011 04:33:10 am Vineet Deodhar wrote:
> Thanks John & Paul.
>
> ### (excessive quoting is removed for readability)
>
> I looked at the RowCount of distBizObj.
> It is only 2.
> There are total 31 records in the 'dist' table in MySQL DB.
> Upon looking closely, I found that the only those 'dist' records are
> fetched which have statid=1. For your ready ref., my modified code is like
> this---
>
> ### code start ###
> #connection object
> ci = dabo.db.dConnectInfo(Host='localhost', DbType='MySQL',
> Database='whlbel', User='root', PlainTextPassword='123') conn =
> dabo.db.dConnection(ci)
> class PublicDistBizobj(dabo.biz.dBizobj):
> def afterInit(self):
> self.DataSource ='dist'
> self.KeyField = 'distid'
> self.addFrom('dist')
> self.addField('distid')
> self.addField('distnm')
> self.addField('statid')
> self.NonUpdateFields = ['distid']
>
> class PublicStatBizobj(dabo.biz.dBizobj):
> def afterInit(self):
> self.DataSource = 'stat'
> self.KeyField = 'statid'
> self.addFrom('stat')
> self.addField('statid')
> self.addField('statnm')
> self.NonUpdateFields = ['statid']
>
> statBizObj = PublicStatBizobj(conn)
> distBizObj = PublicDistBizobj(conn)
> distBizObj.LinkField = 'statid'
> distBizObj.FillLinkFromParent = True
> statBizObj.addChild(distBizObj)
> statBizObj.requery()
> distBizObj.requery()
> ### code end ###
>
> At the interactive prompt, I tried this --
>
>
> >> from dabovmd import bo # 'bo.py' is in 'dabovmd' folder
> >> bo.distBizObj.RowCount
>
> 2
>
> >> for rownum in bo.distBizObj.bizIterator():
> ... rec = bo.distBizObj.Record
> ... print rownum, rec.distid, rec.distnm, rec.statid
> ...
> 0 1 stat1 1
> 1 25 stat2 1
> (actually there are 31 recored in the MySQL DB)
That is correct. What this is saying is
table stat is on the record with statid = 1
Therefore, table dist is filtered to only the records where
dist.statid = 1. Even if there are 31 records in dist you will only see the
records that relate to the stat table PK. So whatever record you are on in
stat will filter the records in dist.
If you changed the stat table (moved the record pointer) so that the table
stat had a record where statid = 2 then the dist table would be filtered to
all the records where dist.statid = 2 would appear (there may or may not be
records with dist.statid=2)
>
> for table 'stat', the same procedure is working correctly.
> Then, just for testing, I commented out the following statement--
> #distBizObj.LinkField = 'statid'
This removes the parent ->child relationship.
> And now I am getting all the 'stat' bizobj contents.
> I can seek() and setFieldVal() and save() it.
When your program did
"statBizObj.requery()" it retrieved the 'all' records for the table stat. If
you add the following just below "statBizObj.requery()"
print statBizObj.RowCount
Please tell me what that prints - because that is the number of records that
were retrieved.
> I think some filter is causing this behaviour, when the 'LinkField' is
> specified (only those rows with statid=1 are fetched from dist table).
> Can you pl. suggest on the points below ---
>
> 1) whether it is OK to comment-out that line?
IMO No.
> 2) whether the PK of parent table would by default be taken as the FK in
> child table? (as we have addChild method called).
No that is incorrect
> 3) Even if 1) & 2) are OK, there will be a situation in cases where the FK
is not the primary key of parent table ,but some other field in that table is
FK for child table. What to do in such cases?
Dabo does not care if the actual link field is a PK or not. All that is
required is the link field be there.
Most parent ->child relationships are "one to many" but there are others (I
will not discuss them until you get this fixed). So far what you have
provided is a straight forward parent->child. As long as the parent table
contains the link field and you setup the child table to have the FK as a
field - Dabo can use it.
>
> Thanks,
> Vineet
_______________________________________________
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]