[comp.sys.mac.apps] Relational files in 4D

cmacfarl@trocadero.ICS.UCI.EDU (02/15/91)

I would like to know if it is possible to do the following:

I have set up a relational database such that you have a People
file and a Company file.  With a many to one relation between
[People]Company and [Company]CompanyName.  This allows you to relate
many people in the People file to one company in the Company file.

My question is, is there any way to change the name of a company in the
Company file and have that change reflected automatically in all the people
in the People file?

For example, if I have a database with a company called XYZ and many people
related to that company and the company changes its name to ABC then how
does the People file get updated to correspond with the changed name in
the Company file?

Many thanks,
Craig

alex@eniac.seas.upenn.edu (Edmund Davis) (02/15/91)

There is no automatic function for updating the many file when the related
one-field changes.  You must write a script more-or-less as follows:

(Place it in the [Company]CompanyName field and set the Only if Modified flag)

relate many([Company]CompanyName)
$new:=[Company]CompanyName
apply to selection([People];[People]Company := $new)



that's it.

alex

----
Edmund A. Davis			      Internet:	alex@eniac.seas.upenn.edu
ACIUS Registered Developer             US Mail:	233-F So. Melville St.
						Philadelphia, PA 19139
					  	(215) 386-3305

francis@wolfman.cis.ohio-state.edu (RD Francis) (02/16/91)

In article <37592@netnews.upenn.edu> alex@eniac.seas.upenn.edu (Edmund Davis) writes:
   There is no automatic function for updating the many file when the related
   one-field changes.  You must write a script more-or-less as follows:

   (Place it in the [Company]CompanyName field and set the Only if Modified flag)

   relate many([Company]CompanyName)
   $new:=[Company]CompanyName
   apply to selection([People];[People]Company := $new)

Along the more or less lines, it's important to note that (unless it's
one of the things that got changed with version 2.0) local variables
($<varname>) don't carry their definitions into APPLY TO SELECTION
commands; try replacing $new above w/ NewCoName or something like
that, to get better results.
--
R David Francis   francis@cis.ohio-state.edu

alex@eniac.seas.upenn.edu (Edmund Davis) (02/18/91)

In article <FRANCIS.91Feb15113318@wolfman.cis.ohio-state.edu> francis@wolfman.cis.ohio-state.edu (RD Francis) writes:

>
>Along the more or less lines, it's important to note that (unless it's
>one of the things that got changed with version 2.0) local variables
>($<varname>) don't carry their definitions into APPLY TO SELECTION
>commands; try replacing $new above w/ NewCoName or something like
>that, to get better results.
>--
>R David Francis   francis@cis.ohio-state.edu

Yes, in ver. 2.1.1, $var (local variables) do retain their values throughout
an APPLY TO SELECTION command.  I am not sure when exactly this was implemented
but I just tested it and it works fine.  (Although, I have had some
inexplicable difficulties with pointers and indirection along these lines...)

In the given example, you _probably_ could have simply specified the field
name itself, but I haven't checked this out.

alex
----
Edmund A. Davis			      Internet:	alex@eniac.seas.upenn.edu
ACIUS Registered Developer             US Mail:	233-F So. Melville St.
						Philadelphia, PA 19139
					  	(215) 386-3305