dbTalk Databases Forums  

changing match value w/o breaking relationship

comp.databases.filemaker comp.databases.filemaker


Discuss changing match value w/o breaking relationship in the comp.databases.filemaker forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
jbpollock@gmail.com
 
Posts: n/a

Default changing match value w/o breaking relationship - 12-08-2005 , 12:34 PM






Hello all,

I have two quick questions:

1) If making a relationship between two tables, is it necessary to make
the match field a field that the user is not going to change? Here's
the problem I'm running into: if I have a match field called "name" and
change its value in table 1, the value of "name" in table 2 will not
automatically change at the same time, and this breaks the match
relationship. I realize I can associate the tables using a unique
identifier field that the user won't need to touch, but I'm wondering
if that's really necessary or whether it's possible to tell Filemaker,
"if the match field value in table 1 changes, change the match field
value in table 2 to the same value."

2) If I import a bunch of records into table 2, those records will line
up with records in table 1 provided that the match field value in the
import file is the same as a value in table 1. But what if there are
records in the import file whose names don't match anything in table 1?
Is there a way to tell Filemaker to create associated records in table
1 if there's no match?

Thanks all, and sorry for starting the other confused thread. I've
been able to sort through my confusion to the point where I can post
these somewhat clearer questions.


Reply With Quote
  #2  
Old   
Matt Wills
 
Posts: n/a

Default Re: changing match value w/o breaking relationship - 12-08-2005 , 01:24 PM






jbpollock (AT) gmail (DOT) com wrote:

Quote:
Hello all,

I have two quick questions:

1) If making a relationship between two tables, is it necessary to
make the match field a field that the user is not going to change?
Here's the problem I'm running into: if I have a match field called
"name" and change its value in table 1, the value of "name" in table
2 will not automatically change at the same time, and this breaks the
match relationship. I realize I can associate the tables using a
unique identifier field that the user won't need to touch, but I'm
wondering if that's really necessary or whether it's possible to tell
Filemaker, "if the match field value in table 1 changes, change the
match field value in table 2 to the same value."
Sure, as long as you can figure out how to associate the new key to the
old one, so FileMaker can search out occurrences of the old one and
change it to the new. Once the name in Table1 changes, how is FileMaker
supposed to know what the old key was so it can be searched out and
changed?

Quote:
2) If I import a bunch of records into table 2, those records will
line up with records in table 1 provided that the match field value
in the import file is the same as a value in table 1. But what if
there are records in the import file whose names don't match anything
in table 1? Is there a way to tell Filemaker to create associated
records in table 1 if there's no match?
You can create a calc field in Table 2 that determnines if there are
matching records in Table1 and create records where there are none.
COnsiderably easier than the first scenario.

Matt



--



Reply With Quote
  #3  
Old   
Matt Wills
 
Posts: n/a

Default Re: changing match value w/o breaking relationship - 12-08-2005 , 02:53 PM



Matt Wills wrote:

Quote:
jbpollock (AT) gmail (DOT) com wrote:

Hello all,

I have two quick questions:

1) If making a relationship between two tables, is it necessary to
make the match field a field that the user is not going to change?
Here's the problem I'm running into: if I have a match field called
"name" and change its value in table 1, the value of "name" in table
2 will not automatically change at the same time, and this breaks
the match relationship. I realize I can associate the tables using
a unique identifier field that the user won't need to touch, but I'm
wondering if that's really necessary or whether it's possible to
tell Filemaker, "if the match field value in table 1 changes,
change the match field value in table 2 to the same value."
Upon further consideration:

While I am sure the overwhelming majority would highly recommend
against changing the key in any relationship, it would still be
possible.

My idea:

Create a second ID field for each record. Let's call them Table1::Key1
and Table1::Key2. Create two relationships: Table1:Key1 = Table2::Key2,
and Table1:Key2 = Table2::Key1.

Use EventScript (free plugin) to trigger a script if the value of
Table1::Key1 changes. Since the primary relationship no longer exists,
this script would use the second relationship to change the value of
the child records Table2::Key1 to the new value from Table1:Key1.

When all that is done, make the Table1::Key2 equal Table1::Key1.

You would need a mechanism to assure that the initial values of the two
ID fields in Table1 are the same. This could be built in to the
beginning of the script triggered by EventScript:

If isEmpty [ Table1::Key2 ]
Set Field [ Table1::Key2 ; Table1::Key1 ]
Exit Script

Like I said, you're not liable to garner much support for the idea from
very many people, including me. The potential for lost child records
through the break in relationship is enough to stay away from it.

The best method is to have an ID Key that will never be changed
automatically set upon creation of the record. With a unique,
unchanging ID key in place, you change what you want in the records as
often as you want, and they stay related.

Out of curiosity, why would you want to go to all this trouble in the
first place? Why is the simplicity of a unique unchanging ID Key not
suitable?

Matt


Reply With Quote
  #4  
Old   
jbpollock@gmail.com
 
Posts: n/a

Default Re: changing match value w/o breaking relationship - 12-08-2005 , 06:34 PM



Matt,

Thanks much! Your answer is pretty much what I expected. And in
answer to your question:

Quote:
Out of curiosity, why would you want to go to all this trouble in the
first place? Why is the simplicity of a unique unchanging ID Key not
suitable?
It's probably not worth trying to explain the convoluted scheme I had
in my head. And part of it was that I had already done a bunch of
match fields without using a unqiue id and was hoping i might avoid
having to change all the relationships. But obviously that's not a big
deal, and doing anything else would be ugly.

I'll also look into doing a calc field to check for missing records;
that'll be helpful.

Thanks again!



Reply With Quote
  #5  
Old   
Bill
 
Posts: n/a

Default Re: changing match value w/o breaking relationship - 12-09-2005 , 08:20 AM



In article <1134088474.914545.232330 (AT) g14g2000cwa (DOT) googlegroups.com>,
"jbpollock (AT) gmail (DOT) com" <jbpollock (AT) gmail (DOT) com> wrote:

Quote:
Matt,

Thanks much! Your answer is pretty much what I expected. And in
answer to your question:

Out of curiosity, why would you want to go to all this trouble in the
first place? Why is the simplicity of a unique unchanging ID Key not
suitable?

It's probably not worth trying to explain the convoluted scheme I had
in my head. And part of it was that I had already done a bunch of
match fields without using a unqiue id and was hoping i might avoid
having to change all the relationships. But obviously that's not a big
deal, and doing anything else would be ugly.

I'll also look into doing a calc field to check for missing records;
that'll be helpful.

Thanks again!
Some thoughts:

1. In almost all circumstances, it is best to use as match fields (or
"Key fields" in more standard Filemaker usage), fields whose content
does not change and is not editable by the user. The automatically
assigned serial number in the "parent" table and a corresponding number
field in the child table is the usual method.

2. It is possible to change key fields from one scheme to another in a
straightforward and reliable way. In the following discussion, I assume
the existing relationship is based on key fields named OrgName in both
tables.

a. Set up the new key fields in both tables. For the sake of discussion,
call them kpParentID in the parent table, and kfParentID in the child
table. Both are number fields.

b. Define kpParentID in the parent table to be a serial number, next
value 1, increment 1.

c. In the parent table, show all records, then go to the kpParentID
field and do Replace Field Contents with Serial number, starting value
1, increment 1, with Update serial number in entry options checked.

d. In the parent table, go to the field definition for kpParentID,
verify that the next value of the serial number has been updated to be
one more than the numbers automatically entered in step c, then check
the box Prohibit modification of value during data entry.

e. In the child table, Show all records, then go to the field
kfParentID, and do Replace field contents, with a calculation, the
formula being
kfParentID = Parent::kpParentID.

This will put the value of the kpParentID in the field kfParentID of
each record of the child table, based on the existing relationship
between them.

f. Redefine the relationship between the two tables to be based on the
ParentID field instead of the Org Name field.

Now you can edit the OrgName field and it will not break the
relationship. You can even delete the OrgName field from the Child
table, and simply put the related OrgName field from the parent table in
layouts of the Child table. That way, they will always be the same.

The field definition prevents a user from editing kpParentID in the
parent table. To prevent a user from editing kfParentID in the child
table, leave that field out of most layouts of the Child table, and for
those layouts contain that field, format the field so that the user can
not enter the field in the browse mode. The user does not need to see or
use that field, so it can be left out of practically all layouts.

3. To find orphan records, put a related field from one table (Table A
for discussion) into a layout of the other table (Table B). Pick a field
that you know always has a value in Table A. In Table B, do a Find for
records in which that related field is empty. All the empties are orphan
records in Table B.

Bill Collins

--
For email, remove invalid.


Reply With Quote
  #6  
Old   
jbpollock@gmail.com
 
Posts: n/a

Default Re: changing match value w/o breaking relationship - 12-09-2005 , 03:23 PM



Thanks Bill! This is extremely helpful info, particularly the tip
about locating the orphans.


Reply With Quote
  #7  
Old   
FP
 
Posts: n/a

Default Re: changing match value w/o breaking relationship - 12-09-2005 , 09:46 PM



Bill wrote:
Quote:
3. To find orphan records, put a related field from one table (Table A
for discussion) into a layout of the other table (Table B). Pick a field
that you know always has a value in Table A. In Table B, do a Find for
records in which that related field is empty. All the empties are orphan
records in Table B.
I agree with everything Bill says except the part about locating orphan
records. You can not find orphan records by searching related data
because they don't have a related record. Even searching for an empty
related field will not find orphan records. What you can do instead is
search for all records that have data in a related field and then find
omitted records; these are the orphans.



Reply With Quote
  #8  
Old   
Bill
 
Posts: n/a

Default Re: changing match value w/o breaking relationship - 12-10-2005 , 01:01 PM



In article <1134186412.087774.296940 (AT) g47g2000cwa (DOT) googlegroups.com>,
"FP" <ab (AT) pottnerconsulting (DOT) ca> wrote:

Quote:
Bill wrote:
3. To find orphan records, put a related field from one table (Table A
for discussion) into a layout of the other table (Table B). Pick a field
that you know always has a value in Table A. In Table B, do a Find for
records in which that related field is empty. All the empties are orphan
records in Table B.

I agree with everything Bill says except the part about locating orphan
records. You can not find orphan records by searching related data
because they don't have a related record. Even searching for an empty
related field will not find orphan records. What you can do instead is
search for all records that have data in a related field and then find
omitted records; these are the orphans.
That is true. I was perhaps too cryptic in my explanation. Do a Find
that omits records than have data in the related field. The remaining
records are the orphans.

Bill Collins

--
For email, remove invalid.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.