|
|
|
Navigate: | My Mac Online | The Archives | June 1999 | FileMaker 101 - Part 15 | |
![]() |
|
![]() Part 15
My Mac Magazine manavesh@mymac.com
Self-Relationships with ID Fields This month I'm going to go on a bit more about self-relationships. They are one of the most useful tools for identifying records within a file. You can use these self-relationships for many things that would normally require a Find operation (which can be slow, especially with many records), do many things that would require a summary report (also slow, and requiring a change to Preview mode), and easily do things that would be very difficult otherwise. If you haven't done anything much with relationships, these are a good way to start. The "self" part of the name just means that both sides of the relationship are fields within the same file.
Self-ID Relationship There are several uses for self-relationships. There are two basic possibilities for an ID field in a file. The first is that it is unique for each record in the file. The other is that it isn't unique, that there are of several instances of it in the file. In the first case, you may not even use a self-relationship on the ID itself. There's not much point, since there's only one; it would usually be an auto-entered serial number and can be validated by the built-in "unique" checkbox.
Duplicates (again) What I haven't written about before (at least not very clearly) is how to use self-relationships in files where there are several instances of an ID field.
Pseudo Design Theory
Go To All Instances
Calculations The only disadvantage is that they are unstored, and any further calculations based on them will become unstored upon closing the Define Fields dialog. Not only that but they will remain so forever, unless you either remove the related field from the calculation or change it so that it can be indexed; and then also go into the Storage Options of each calculation and manually uncheck the "Do not store results" box! Not being stored can be a feature in some situations. A field with the count of the relationship can show you how many records there are of that ID without even having to perform a find, and it will update if you add or delete records.
Global Self-relationships What this relationship does is to free you from having to use the ID field itself in operations. This becomes essential when you are not actually on the ID's record. Two common cases of this are when you change the found set within scripts, and when you choose records in a portal.
In both cases, all you have to do is to get the real ID value into the global ID field while it is the current record. Then at any later time use these two steps:
Global Self-relationships and Portals For example, if the portal is based on a relationship between a Constant=1 field and a First Entry Mark field (both being number 1, in an earlier article), showing one entry for each ID, the ID in the portal would actually be "Constant::ID." Because you don't have a relationship between this field and your ID field you can't go there directly.
But you can use the global ID field as a go-between. Just set the Constant::ID field into the global first.
Warning
Logical Calculations on the Self-Relationship You can use the same check with Self-Global relationship. This is great to use before the Go To Related Record [Show, "Self-Global relationship"] step. One of the great problems with Go To Related Record [""] is that it will go even if there are no matching records, leaving the user with no records, often on a different layout (or even file), with no error message or clue as to what went wrong. It's even worse than the built-in Find when there's no records.
But you can use the following simple steps: If the script is attached to a button, when the user clicks it and there are no matches nothing will happen. You can put a message if you want, but I like the simple zilch. It is very useful if they are looking at a portal that is based on another file, since there may or may not be records for that ID in this file. The If [IsValid, "Self-ID::ID"] or, alternatively, If [IsValid, "Self-IDg::ID"] check can be used within scripts, whenever you need to check to see if there are records. It is completely independent of the Found set; but it does depend on being on the record with the correct ID or getting the ID into the global ID field (and using the Exit Record/Request step).
Counting a Global Self-Relationship
Self-Relationships vs. Finds In many cases, especially during complex scripts, self-relationships are invaluable, because of the extra control they give you. So, next time you get in a tight spot trying to bring things together (or keep them apart), consider whether one of these small relationships could help get a handle on that pesky data. My Mac Turns 50 Happy Anniversary to us all! Back in the early days of my Internet adventure (about three years ago), it wasn't so easy to find much material on the web. It was even more unstable than it is now (if you can believe that), and at 2400 baud it was like watching an old movie in slow motion. So I was very happy to find a little magazine devoted to Macs. I could read about the little shareware programs that were (and still are) so essential to make your Mac easier and more fun to use. I spent a lot of time trying them out and learning quite a bit about the computer in the process. I remember sending an email to Tim, probably pointing out a little program that I thought he should review. I was quite surprised at his response, which was basically, "You write pretty well, why don't you write a review?" I began with URL Manager, which I still use daily. I then followed that for several months with all the little programs I loved, BBEdit Lite, Eudora Light, Snap-To. That was over two years ago, and I haven't stopped. A little while later I fell for FileMaker Pro, and after a review and an introductory column, I was off on my tutorial series, FileMaker 101. It has been a labor of love (though it isn't always an easy application to love). I write about what I've learned by hard effort (trial and lots of error), as well as the helpful tips I've picked up in many places on the web, especially the FileMaker mailing lists. I write not so much to create a textbook or manual but to share the little tricks and techniques that allow you to go beyond step one. I try to stay focused and be clear, but I also allow myself to write about what interests me, and in my own style, rather than formal "technical writing." It is an informal column, though its contents are pretty geeky. I want to thank Tim, Russ, Adam, and all the other writers who spend so much time making this all happen. Their dedication and openness makes it possible. We all do this simply because we want to do it, and we want to share it with you, our readers. I know that if I write sincerely I will be supported. And that if I manage to pull together the various bits of knowledge into a coherent article it will help someone, and save them some time and frustration, and maybe occasionally make them jump up and say, "Ah ha! That's how you do it." (I do that anyway.) It also helps me; by explaining it to others I'm forced to get it clear for myself. I even remember most of it : ) The last thing I want to say is that you who are reading this are part of the My Mac team. Anything you have to say on the subject is important. So write to the authors with your praise, criticism, or questions. In the future we hope to be able to include you even more directly. We are a community, we Mac users.* We've seen some low times and some high times. But we've always helped each other. *FileMaker users are another community, reaching across platform lines; I'm sure many of my readers use PCs. I look forward to the day when all documents and applications are fully interchangeable. Computers have become too important to the world to be limited by incompatibilities. See you next month with more on relationships and some fun with portals.
Fenton Jones
FileMaker 101 - Previous Columns
|
|
Copyright ©1995-2000 My Mac Productions, All Rights Reserved |