How to access child objects in hierarchical database setup
Ruslan Zasukhin
sunshine at public.kherson.ua
Sun Nov 2 17:42:23 CST 2003
on 11/2/03 15:51, Arthur Clemens at aclemens at xs4all.nl wrote:
> Then I retrieve the SloveneWord
> with the method itemAtIndex:
>
> - (id)itemAtIndex:(int)index
> {
> mIterator->GoTo(index);
> FBL_REC_ID RecID = **mIterator; // mIterator is set up as pointer,
> hence the double **
> // ... have the RecID and now what?
> }
>
> All works - I get the record id. But now: how does the Record know of
> its children? Do I need to set up a Find to retrieve all SloveneWords
> with mfParentPtr equals the record id? (Like in the Plant example, the
> very last page?) Or is it faster to let Record have pointers to its
> children, for instance:
>
> VDK_ObjectPtr mfSloveneWordPtr; // pointer to boSloveneWord
>
> ... and then to access them directly?
You cannot do this.
Your structure must looks as:
PARENT_Table CHILD_Table
1 : M
ObjectPtr to parent table
I.e. CHILD table keep pointers to Parent table.
ALWAYS. This is RULE!
Because pointer can points only one record.
Back to your question.
Let you have RecID of some ParentTable record,
Now you want find its child records.
You need do simply:
ArraySet* pChilds = childTable.ptr.FindAsArraySet( &RecID );
Note, since in most cases the count of childs will not be not huge, it is
better to use ArraySet.
--
Best regards,
Ruslan Zasukhin [ I feel the need...the need for speed ]
-------------------------------------------------------------
e-mail: ruslan at paradigmasoft.com
web: http://www.paradigmasoft.com
To subscribe to the Valentina mail list go to:
http://lists.macserve.net/mailman/listinfo/valentina
-------------------------------------------------------------
More information about the Valentina
mailing list