Understanding Table Context

 <  Day Day Up  >  

FileMaker 7 differs greatly from previous versions in its capability to work with many database tables in a single physical file. But there's a bit of a price to be paid for this power. Many, if not most, actions in FileMaker 7 assume that some particular table is somehow the "active" table. Say you reach up to the Records menu and select Delete Record. Which table does that command affect? It affects the "current" table ”but how does FileMaker decide which table is "current"? The answer is that FileMaker determines this from what's called the table context .

Table context, it turns out, is determined by the currently active layout. Let's continue to refer to the Town/TownOfficer example. The steps to add the new table were simple, but there's some complexity underneath. After you're back in the Town database, you're still probably looking at the town entry layout, the one where you can view basic town information. But FileMaker has silently added another layout to the database.

In Layout mode, make sure the status area is showing and click on the layout popup list near the top of the Status Bar. There are now two layouts: one called Town, the other called TownOfficer. The new layout is named for the second table you added. You've already learned how the displays in the Status Area work. Add a few records while you're on the Town layout, and you'll see the total number of records, as listed in the status area, grow. More towns, more records ”no big surprise there.

But if you use the layout popup list to switch to the TownOfficer layout, a surprise is in store: The record total drops back to zero. Why?

The simple answer is that each layout is showing something different. The Town layout shows records from the Town table, and the TownOfficer layout shows records from the TownOfficer table. These tables can, and probably will, have different numbers of records. To make the concept still clearer, go ahead and add a bunch of records while you're on the TownOfficer layout. For TownID , pick some of the IDs of towns you've already created ”they'll probably be low numbers such as 1 “5. You may want to choose V iew, View as Tabl e to see the list in its entirety as it grows. Now switch back and forth between the two layouts to see the record totals shift.

In FileMaker 7, each layout represents a view into a particular database table. If you think back to the analogy of a database table as a card file, you can think of each table as a file containing a different kind of card. In the Town card file, each card holds information about one particular town. In the TownOfficer card file, each card holds information about a town officer in one of those towns. When you move from one layout to another in FileMaker, it's as though you're closing one card file and opening up another. Each new card file you open may have a different number of cards, with different information on each card.

FileMaker keeps track of all this by storing a table context with each layout. To see this, drop into Layout mode on the Town layout and choose L ayouts, La y out Setup. Notice the menu that says Show Records From (you can see it in Figure 6.8). If you click on that menu, it lists all the tables for this database and shows that the layout is currently linked to the Town table.

Figure 6.8. This is the Layout Setup dialog, showing the table context for the TownOfficer layout.

graphics/06fig08.jpg


In practice, you're unlikely to need to change the table context of a layout after it's been established. When you create a new table in a database, FileMaker adds the new table to the Relationships Graph, and also adds a new layout based on the table. You may, though, want to create additional layouts that refer to the same underlying table. In that case, you need to set the table context for the layout in the course of creating the layout. Again, you're unlikely to need to change this after it's been set. If you have a working layout that's displaying data from a particular table, you're likely to discover odd consequences if you change the table context.

NOTE

There's some simplification in that last paragraph. Here's a more accurate rendition of the second sentence : "When you create a new table in a database, FileMaker adds a table occurrence for the new table to the Relationships Graph, and also adds a layout based on that table occurrence." The full importance of the distinction is made clear in the next chapter.


For a discussion of table occurrences, see "Adding a Table Occurrence to the Relationships Graph," p. 183 .


 <  Day Day Up  >  


QUE CORPORATION - Using Filemaker pro X
QUE CORPORATION - Using Filemaker pro X
ISBN: N/A
EAN: N/A
Year: 2003
Pages: 494

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net