parent-child in a form 
Author Message
 parent-child in a form

Hi all,

Is there a bug in the form template when I have a simple parent-child
relation in a form.  for example I have a browse for the parent file,
the browse (parent) have an update procedure (form), in the parent
form I have a child browse box.

** it will only work when I change my parent id field to auto-
   increment with unique attribute.

** when I change uncheck the auto-increment and allow entry in the
   parent id field.  when I press insert on the parent browse box and
   up my update form for the parent file, enter some value in the
   parent id, parent name, and the press insert to call child update
   form, I notice that the child's parent id is not prime and right
   after the child update form is completed, it clear the parent id
   field.  
  why it only work with auto-increment field in my situation ?

please help,

thanks
Ryan
---------------------------------------------------------------------
System Programmer                                                    

---------------------------------------------------------------------



Sat, 28 Nov 1998 03:00:00 GMT  
 parent-child in a form


-->Hi all,
-->
-->Is there a bug in the form template when I have a simple parent-child
-->relation in a form.  for example I have a browse for the parent file,
-->the browse (parent) have an update procedure (form), in the parent
-->form I have a child browse box.
-->
-->** it will only work when I change my parent id field to auto-
-->   increment with unique attribute.
-->  
-->** when I change uncheck the auto-increment and allow entry in the
-->   parent id field.  when I press insert on the parent browse box and
-->   up my update form for the parent file, enter some value in the
-->   parent id, parent name, and the press insert to call child update
-->   form, I notice that the child's parent id is not prime and right
-->   after the child update form is completed, it clear the parent id
-->   field.  
-->  why it only work with auto-increment field in my situation ?
-->  
-->please help,
-->
-->thanks
-->Ryan

Hi Ryan,

As we say here, it's a Fire game, very dangerous by nature ! You should NEVER allow user
entry in a relational field. This being said, you have to understand that the template, if
you have an auto-increment field, calculate this one, then add a record to the file, so
that the new ID number is in memory, and usable to prime a child record, else, your record
is added only while pressing the OK button.

Said differently, if you use auto-inc field, the template do the work for you, else you
have to take care of the whole process yourself, and don't forget to cascade changes if
you allow them....

For myself, I never allow user to even SEE the auto-inc ID field, and all the relations
are build onto this field, unique, auto-increment, and there is only one cascade, delete,
following the nature of the project/file. This allow very robust databases....

HTH,

Bernard Grosperrin - BG Consultants - Team Topspeed Internet
'Just trying to do my best with THE best tool'
at %T^H^H^H on %D using OzWin II v%V



Sun, 29 Nov 1998 03:00:00 GMT  
 parent-child in a form

Hi Ryan

1) If you have a dictionary relation between the parent and child:
From the browse properties, hang the child file off the parent file
       ParentFile
           +- ChildFile
The template code will prime the child key fields. This will be done
in the browse for the parent (or parent form for the child)

2) If you do not have a dictionary relation:
Fields can be primed in the
       Browse Box, before Insert
             +- Update a Record from Browse Box on Child

Note that if you have a child browse on a parent form: If the user
adds children and then cancels the parent, the children will be
orphaned. You have to add your own code to take care of this.

Regards
Malcolm

Quote:
> Hi all,

> Is there a bug in the form template when I have a simple parent-child
> relation in a form.  for example I have a browse for the parent file,
> the browse (parent) have an update procedure (form), in the parent
> form I have a child browse box.

> ** it will only work when I change my parent id field to auto-
>    increment with unique attribute.

> ** when I change uncheck the auto-increment and allow entry in the
>    parent id field.  when I press insert on the parent browse box and
>    up my update form for the parent file, enter some value in the
>    parent id, parent name, and the press insert to call child update
>    form, I notice that the child's parent id is not prime and right
>    after the child update form is completed, it clear the parent id
>    field.  
>   why it only work with auto-increment field in my situation ?

> please help,

> thanks
> Ryan
> ---------------------------------------------------------------------
> System Programmer                                                    

> ---------------------------------------------------------------------



Sun, 29 Nov 1998 03:00:00 GMT  
 parent-child in a form

Hi Malcolm,

It work ! and thank you very much...
sincerely,

Ryan

Quote:


>>Date sent:      Wed, 12 Jun 1996 23:59:15 +0200
>>Subject:        Re: parent-child in a form

>>Priority:       normal
>>Hi Ryan

>>1) If you have a dictionary relation between the parent and child:
>>From the browse properties, hang the child file off the parent file
>>       ParentFile
>>           +- ChildFile
>>The template code will prime the child key fields. This will be done
>>in the browse for the parent (or parent form for the child)

>>2) If you do not have a dictionary relation:
>>Fields can be primed in the
>>       Browse Box, before Insert
>>             +- Update a Record from Browse Box on Child

>>Note that if you have a child browse on a parent form: If the user
>>adds children and then cancels the parent, the children will be
>>orphaned. You have to add your own code to take care of this.

>>Regards
>>Malcolm

>>> Hi all,

>>> Is there a bug in the form template when I have a simple parent-child
>>> relation in a form.  for example I have a browse for the parent file,
>>> the browse (parent) have an update procedure (form), in the parent
>>> form I have a child browse box.

>>> ** it will only work when I change my parent id field to auto-
>>>    increment with unique attribute.

>>> ** when I change uncheck the auto-increment and allow entry in the
>>>    parent id field.  when I press insert on the parent browse box and
>>>    up my update form for the parent file, enter some value in the
>>>    parent id, parent name, and the press insert to call child update
>>>    form, I notice that the child's parent id is not prime and right
>>>    after the child update form is completed, it clear the parent id
>>>    field.  
>>>   why it only work with auto-increment field in my situation ?

>>> please help,

>>> thanks
>>> Ryan
>>> ---------------------------------------------------------------------
>>> System Programmer                                                    

>>> ---------------------------------------------------------------------

>>---------------------------------------------------------------------

System Programmer                                                    

---------------------------------------------------------------------


Sun, 29 Nov 1998 03:00:00 GMT  
 parent-child in a form

Quote:


>-->Hi all,
>-->
>-->Is there a bug in the form template when I have a simple parent-child
>-->relation in a form.  for example I have a browse for the parent file,
>-->the browse (parent) have an update procedure (form), in the parent
>-->form I have a child browse box.
>-->
>-->** it will only work when I change my parent id field to auto-
>-->   increment with unique attribute.
>-->  
>-->** when I change uncheck the auto-increment and allow entry in the
>-->   parent id field.  when I press insert on the parent browse box and
>-->   up my update form for the parent file, enter some value in the
>-->   parent id, parent name, and the press insert to call child update
>-->   form, I notice that the child's parent id is not prime and right
>-->   after the child update form is completed, it clear the parent id
>-->   field.  
>-->  why it only work with auto-increment field in my situation ?
>-->  
>-->please help,
>-->
>-->thanks
>-->Ryan
>Hi Ryan,
>As we say here, it's a Fire game, very dangerous by nature ! You should NEVER allow user
>entry in a relational field. This being said, you have to understand that the template, if
>you have an auto-increment field, calculate this one, then add a record to the file, so
>that the new ID number is in memory, and usable to prime a child record, else, your record
>is added only while pressing the OK button.
>Said differently, if you use auto-inc field, the template do the work for you, else you
>have to take care of the whole process yourself, and don't forget to cascade changes if
>you allow them....
>For myself, I never allow user to even SEE the auto-inc ID field, and all the relations
>are build onto this field, unique, auto-increment, and there is only one cascade, delete,
>following the nature of the project/file. This allow very robust databases....
>HTH,
>Bernard Grosperrin - BG Consultants - Team Topspeed Internet
>'Just trying to do my best with THE best tool'
>at %T^H^H^H on %D using OzWin II v%V

I agree with Bernard on this one, though I have used user-updatable
link fields in a couple of situations.

Basically the problem is, with autoincrement you have, when you enter
the procedure:

Parent record is primed
Child browse is initialised

before you get to any user input

If you don't have AutoInc working the child browse is initialised with
the PAR:ID of 0 (or blank).

So what you need to do is repopulate the child browse right after the
user updates the parent key field -- i.e. just put:
ForceRefresh = True
do RefreshWindow

in the embed point: Accepted for the parent key field.  
So why does the child update form not get properly initialised? Note
that in the standard templates the priming is done from the current
value of the key fields when the update form is entered, i.e.
CHI:ParID = SAV::CHI:ParID

and not

CHI:ParID = Par:ID

Filling the child file field with the correct value is something that
RefreshWindow accomplishes on the parent form, among (many) other
things.

----------------------
Jon Waterhouse
Andy Rowe Consultants,
St. John's NF



Mon, 30 Nov 1998 03:00:00 GMT  
 parent-child in a form

There is no bug Ryan,
The CW wizards produce this type of form by default if you have
relationships set up in the dictionary.

The reason why it works when you have an auto-increment key is because after
the autoincrement code is completed, the record is saved to disk by the
template code.  If you don't have an autoincrement key the record is not
saved until after the OK button is pressed.

The second problem you have is that in the 'Files' section of the procedure
properties you have the Parent and Child records linked.  This causes the
update to the child procedure to re-get the parent record, which it can't do
if you don't have the auto-increment key!

Two things you should do...

1.  Always use an auto-increment unique key in every file, to create a
PRIMARY key for each file.  Never allow users to change primary, or unique
key fields!

2.  Separate the files in the form procedure so that the Parent form file is
not shown as linked to the child file in the browse list box.

The Video application example probably has an example of this type of Form
procedure.

Cheers,  geoff B


Quote:
>Hi all,

>Is there a bug in the form template when I have a simple parent-child
>relation in a form.  for example I have a browse for the parent file,
>the browse (parent) have an update procedure (form), in the parent
>form I have a child browse box.

>** it will only work when I change my parent id field to auto-
>   increment with unique attribute.

>** when I change uncheck the auto-increment and allow entry in the
>   parent id field.  when I press insert on the parent browse box and
>   up my update form for the parent file, enter some value in the
>   parent id, parent name, and the press insert to call child update
>   form, I notice that the child's parent id is not prime and right
>   after the child update form is completed, it clear the parent id
>   field.  
>  why it only work with auto-increment field in my situation ?

>please help,

>thanks
>Ryan
>---------------------------------------------------------------------
>System Programmer                                                    

>---------------------------------------------------------------------

       _______________________________

                Geoff Bomford
                 ComForMark
       Computer services For Marketing

            Phone: 612 9997 4251  
            Sydney,    Australia
       _______________________________



Mon, 30 Nov 1998 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. SQL - adding child record from parent form

2. Add Child Record Within New Parent Record form.

3. Parent form cleared when EIP child browse

4. delete parent-child record without using form

5. Child browse in parent form

6. I have Update Form (parent file) with Browse List (child file)

7. Update of Parent Form from Child

8. CW4 Writing to a parent file from child file's update form

9. Scrolling form in a parent child situation

10. Update parent value from child form

11. send data form child to parent

12. Copying grand parent, parent, and child records

 

 
Powered by phpBB® Forum Software