navigate site menu

Start learning with our library of video tutorials taught by experts. Get started

Relational Database Design with FileMaker Pro
Richard Downs

Relational Database Design with FileMaker Pro

with Cris Ippolite

 


Let author Cris Ippolite show you how to translate aspects of the real world into the form and language of a relational database, using three practical data modeling examples. The course begins by reviewing some of the basic concepts of data modeling, introducing tables, key fields, and the Relationship Graph. Then, after demonstrating how to establish relationships in a database, the course concludes with a demonstration of some advanced modeling techniques, such as filtering, scripting, and the use of portals.

The course applies to versions of FileMaker Pro from 7 through the most current version.
Topics include:
  • Reviewing relationships types
  • Diagramming relationships
  • Resolving many-to-many relationships
  • Determining which tables need key fields
  • Defining tables in FileMaker Pro
  • Using the Relationship Graph
  • Using multiple match fields in one relationship
  • Using global fields to filter portals
  • Creating self relationships
  • Creating aggregate functions using relationships

show more

author
Cris Ippolite
subject
Business, Databases
software
FileMaker Pro 10, 11, 12, 9
level
Intermediate
duration
2h 32m
released
Aug 04, 2011

Share this course

Ready to join? get started


Keep up with news, tips, and latest courses.

submit Course details submit clicked more info

Please wait...

Search the closed captioning text for this course by entering the keyword you’d like to search, or browse the closed captioning text by selecting the chapter name below and choosing the video title you’d like to review.



Introduction
Welcome
00:04Hi! I'm Cris Ippolite, and this is Relational Database Design for FileMaker Pro.
00:09In this course I'll discuss the concepts and techniques that you can use to
00:13design a relational Database in FileMaker.
00:16Using real-world examples, I'll show you how to determine which tables you need
00:20to define in your relationship graph, as well as how and why to resolve those
00:24pesky many-to-many relationships.
00:27I'll explain how to use relationships in your scripts and calculations, and
00:31I'll also show you how to use portals, filter portals, and related fields in your layout.
00:36And now it's time for us to dive into Relational Database Design with
00:40FileMaker Pro.
Collapse this transcript
Why relational databases?
00:00Every database is a collection of data which are organized into files called tables.
00:05These tables provide a systematic way of accessing, managing, and updating the
00:09data stored within them.
00:10A relational database is one that contains these multiple tables, but the data
00:15in the tables are related to each other using special key fields.
00:19Conversely, a flat-file database is a database that's designed around a single table.
00:25The flat file design puts all the database information to one table or list with
00:30fields that represent all the different parameters.
00:33Spreadsheets are a common example of flat files.
00:35They store data in different worksheets, and often these different worksheets
00:39contain similar or redundant data.
00:41A relational database, on the other hand, incorporates multiple tables with
00:45methods for these tables to work together.
00:47The relationships between table data can be collated, merged, and displayed in
00:51database forms, or layouts in the case of FileMaker, all representing the
00:55stored data accurately.
00:56FileMaker Pro is an example of a related database system and can store the data
01:00just as easily as a spreadsheet but with data entry and integrity advantages
01:04over its flat-file counterparts.
01:06To understand the advantages of a related database, imagine the needs of
01:10two small companies.
01:11One company is using a series of spreadsheets like the ones I have on screen.
01:15You'll see I've got one flat file storing just customer information and another
01:19flat file storing order information.
01:22Each time an order is placed with this company they have to create a new role in
01:26their Orders table and this means that customer's general information, for
01:29example the first and last name in this case, need to be stored in the same
01:33table as the orders.
01:35If a customer places more than one order, for example in the case of Dennis
01:40Estrella, we have to reenter his first and last name for each order. And wherever
01:46there's duplicate data, as in the case here, many inconsistencies may arise when
01:50users try to search within this database.
01:52Additionally, any change, for example, in the change of the last name of one of
01:56these customers would require the manager of this database to find all the
02:00different rows inside the Orders table and change that name manually each time.
02:06Let's say another organization has the same information, but instead
02:09they're using FileMaker Pro.
02:11I've got an example of FileMaker database that stores all the same information--
02:14customers and orders--and each of the customers has one and only one record of
02:19general information stored inside the Customers table.
02:22We can see those different records as we navigate through them.
02:25When the customer places an order, we create a new record, but what we do is we
02:31pull in related information from the Customer table.
02:35This approach to entering data solves problems of duplicate data and also it makes
02:39making changes to customer information a lot easier.
02:42So now I can just go into Customers, and if I want to change someone's name or
02:46their title or email, I just change it in one spot and then it propagates
02:50appropriately through all the related order records where it's being used.
02:54In addition since the relationships between tables follow the business logic of
02:58the organization using a relational database, it'll make tasks like sharing,
03:02retrieving, and reporting on data much easier and more efficient,
03:06while minimizing data-integrity errors.
03:08We're going to see various different examples of this as we go through the
03:12title, but it's important to know the advantages of having a database like
03:15FileMaker Pro, because your data is going to be related.
03:18This is what we call a related database system.
Collapse this transcript
Using the exercise files
00:00If you're a Premium member of the lynda.com Online Training Library, or if you're
00:04watching this tutorial on a DVD, then you'll have access to the exercise files
00:08used throughout this title.
00:09For example, if you want to just jump to a specific movie, you can find the
00:14specific exercise files that correspond with it.
00:16The way that the exercise files are laid out is that they all come in one folder,
00:20as you see here, and each folder is broken into different chapters.
00:24For example, if you're watching the movie in Chapter 5 movie number two, you
00:28can just click on the subfolder and then double-click on the exercise file to launch it.
00:33In addition, I've added three bonus files to this title under Chapter 6.
00:37These are fully developed sample files that correspond with the
00:40real-world example movies.
00:42If you're a Monthly subscriber or an Annual subscriber to lynda.com, then you
00:46don't have access to the exercise files, but you can easily follow along from
00:49scratch with your own files, so let's go ahead and get started.
Collapse this transcript
1. Reviewing Data Modeling
Introduction to data modeling
00:00In the relational model, data is broken down into small chunks which are
00:03connected to each other by relationships.
00:06By breaking data into smaller pieces accuracy is ensured by making data entry
00:11a one-time process and then reusing the data by connecting it with other pieces.
00:16Using this process, a large collection of unorganized data is simplified into
00:21its smallest units and then related with many other smaller units to re-create
00:25the big picture in a more organized format.
00:28The relational model provides a simple and flexible way to describe data.
00:32Data modeling is the initial purpose of any database.
00:36The data has to be modeled or described so that it can be input and output in a
00:40method that can be duplicated and applied to the business rules of the
00:43organization using the system. And you actually see data organized like this in
00:48the real world all around you.
00:49For example, if you go into to any office, you'll see several file cabinets that
00:54store different files about different things.
00:56One file cabinet, for example, may store information about customers and another
01:00file cabinet may store information just about products, with all that
01:03information organized into their own cabinets, and then within those cabinets
01:07are drawers where the data may be defined in even smaller categories so that
01:11it's more easily accessed.
01:12So just like in this real-world example, the small pieces of data in a
01:17relational model are known as entities.
01:19Once all the information is broken into entities, which will become tables inside
01:23of our database, putting it back together into its original form is done by
01:27creating a relationship between the different tables.
01:31Entities also contain something that are called attributes, which are pieces of
01:35data that describe an entity.
01:37Attributes eventually will become fields inside your FileMaker database.
01:42The process of observing collections of data and then breaking them into
01:45smaller groups and then reassembling them in a logical way is called relational modeling.
01:49The exercise of relational modeling is the first step in constructing the database.
01:53And one important note here is that when you sit down at a computer and you open
01:57up FileMaker Pro to start a new database what you're actually doing there is
02:01constructing something. Much like any other construction project that you would
02:05embark on, like let's say a home construction project,
02:08your database will proceed more smoothly if you first begin with some type of plan.
02:13Relational modeling is like constructing a blueprint for your
02:15FileMaker database.
02:17So the first thing that you really want to do, even before you open up FileMaker,
02:20is come up with a plan, the type of data that you're going to be managing your
02:23system, and therefore what tables you're going to need, and then after you've
02:27determined those things, you'll create the database in FileMaker Pro.
02:29And a lot of people think that they don't have a very complex database solution,
02:34so they can just skip the planning stage, but it's just as important to plan
02:38ahead of time in a simple database as it would be with something very complex.
Collapse this transcript
Reviewing relationships types
00:00When we talk about relationships in database terms, we're talking
00:03specifically about how the different tables are related to each other and how
00:07the relationships between those tables really define the data that's stored within them.
00:11In order to decide in the data model for your database system, it's important to
00:14first determine what the possible kinds of connections are that you could have
00:17between your tables, and then from those, we'll choose the types of connections
00:21that we actually have within the database that we're working on.
00:24So in this movie we're going to quickly review the different types of
00:26relationships, and I'll give explanations of each.
00:29To keep things simple, we're going to focus on three types of relationships that
00:33account for all the situations you're going to encounter within your database
00:35and your data-modeling exercises.
00:37They're called the one-to-one relationship, the one-to-many, or also known as
00:42the man-to-one relationship, and finally the many-to-many relationship.
00:47The first one is called a one-to-one relationship.
00:50It's very rare, and what it means is that you've actually created a table for
00:54something that should actually just be a field.
00:56So, for example, in this case we've got one customer can have only one address
01:01and one address can only be related to one customer.
01:04So the relationship that we have between these two items is just a one to one,
01:07and in this case, as in the other case you've identified a one-to-one
01:12relationship, that means that address is really an attribute of the customer and
01:17therefore should just be a field defined inside the customer table, not its own
01:21table related to the customer table.
01:23So one-to-one relationship simply means an attribute has been improperly
01:27identified as an entity.
01:28So if you go through the process and find out you've got a one-to-one,
01:31you should really just take a look at it, because what you actually might have is
01:34just a field. But the main relationship that you'll want to be familiar with are
01:37the ones that are called one-to-many relationships.
01:40These indicate that you have a parent table that's related to records in a child table.
01:46The parent/child vernacular is common to data modeling and I'm going to be using
01:49a quite a bit in this title.
01:51So what I'm talking about there is that on the one side of the one to many we
01:54call that the parent table and on the many side of them one to many we call
01:58that the child table.
02:00So one parent can have many related children.
02:02You may also encounter relationships that are called many-to-many relationships,
02:06and they should be eliminated.
02:08Many to many means that you've got two related parent tables, but their
02:11relationship is not actually direct, and instead it needs to be related through
02:15an additional child table, so in fact you'll have a one-to-many relationship.
02:19We'll discuss this in detail in the later chapter on many-to-many relationships.
02:24The way that you'll know that you're done with the data-modeling portion of your
02:26database planning is because you will have evaluated all of the possible
02:30relationships between your tables and then determined that all you've got left
02:34are one-to-many relationships.
02:36So that's the first notable learning point here is that you must resolve all of
02:40your relationships into one-to-many relationships, thus removing all
02:43one to ones and all many to manys and leaving yourself with just a series of
02:48connected one-to-many relationships.
02:51Later in this title we're going to look at some examples of relationships that
02:53we might find in our modeling process so we can identify their specific types.
02:57I'm going to use the terminology I have established here a lot in those exercises,
03:01so it's important to define them first.
03:03Whenever I talk about a child table or a child record, I'm talking about a table
03:08or records stored in a table on the many side of a one-to-many relationship.
03:12Whenever I talk about a parent table or parent record, I'm talking about a table
03:17or a record on the one side of the one-to-many relationship.
03:21Once you understand these relationship types and can identify them then you can
03:25move on to diagramming the relationships during your database-planning stages.
Collapse this transcript
Diagramming relationships
00:01So far, we've learned about basic relationship types.
00:04Now let's expand on these techniques and discuss the general method for
00:07diagramming relationships for database systems.
00:10The method we will learn is called creating an entity relationship diagram.
00:15These diagrams are often referred to as ERDs.
00:18It's a simple process that's useful for all types of relational database systems.
00:22Data modeling breaks into three phases.
00:25First, you will look at your information in order to develop a list of entities
00:29which will become tables inside your database.
00:31Next, determine and diagram the relationships between those entities.
00:37Then finally, you will audit the diagram following a couple of rules I will
00:40layout later in this movie.
00:42Let's try one together.
00:44Here's a process description describing requirements of a database system
00:47that we need to build.
00:49In this description, we see the data we need to be storing in our database.
00:54In order to find the entities, it's important for us to identify discrete and
00:58unique buckets of information.
01:01A popular technique for identifying the potential entities is to look for the
01:04nouns within the text of our description.
01:06So go ahead and pause this video and take a moment to read this through.
01:11Using the find-the-nouns technique, we can identify potential entities here as
01:17orders, companies, and contacts.
01:21These each work as entities because they're different, discrete types of data,
01:25and each can be described differently from the others.
01:27So now we have our entity candidate list.
01:31However, just identifying the entities is only part of the process.
01:35Before these entities can become tables in our database, we will need to first
01:39determine how they are related to each other.
01:41And to help us visualize these potential relationships, we will want to create an ERD.
01:46But before we jump into this, I want to show you how entities are represented on an ERD.
01:52In your diagrams it's common to show the entities as a box with the entity name inside of it.
01:58These boxes will eventually represent the tables in your database.
02:02To visually represent these relationships between entities on the diagram, it's
02:07common to draw a line between the two boxes with a double hash mark on the side
02:11that represents the many, or the child, table.
02:15Now we are ready to start exploring the relationships between entities in
02:18our example system.
02:19When you are sketching out potential tables it helps to start asking yourself
02:23questions about how they might relate to each other.
02:25For example, you may want to pick two entities and evaluate the
02:29relationship between them first.
02:31Let's start with companies and contacts.
02:35And the questions we would ask will follow a one-to-many format.
02:38For example, we might ask, can each company potentially have many contacts? Yes.
02:45Let's say that each company should have many individuals working there.
02:49Can each contact be part of more than one company?
02:53No, let's assume that a person can only work for one company at a time.
02:56So data modelers would call the relationship between companies and contacts a
03:00one-to-many relationship and will visually represent the relationship between
03:04these two entities with a line between the two boxes.
03:08The double hash is going to be on the side of contacts because it's the many, or
03:12Child, table in this relationship.
03:15Next, let's evaluate the rest of the relationships by adding the orders
03:19entity to the discussion.
03:20We will start by evaluating whether there is relationship between contacts and orders.
03:27In this situation, we would ask these same one-to-many questions.
03:31Can each contact potentially have many orders in the system?
03:35We will say yes, that could be the goal,
03:37as many orders as possible really.
03:39But can an order be associated with more than one contact?
03:43No, we will say that each order has to be from one contact only.
03:48This tells us that we have another one-to-many relationship between these two
03:51entities with orders as the many.
03:54We will want to represent this on our graph.
03:58Next, we would consider evaluating the relationship between companies and orders.
04:02They are actually already related. Although relationships are not drawn between
04:07the companies and the orders tables directly,
04:10these relationships in between entities are still creating a chain of
04:14associated relationships;
04:16therefore the table on the top of the chain is still related to the table on the bottom.
04:20For example, a company could have a related contact who then places an order;
04:26therefore that order is related to the company associated with that contact
04:31through this chain of relationships.
04:34After you go through these steps determining the relationships between each
04:38entity then your ERD is done.
04:40If you have a small project, kind of like the one that we have used in
04:43this example, it might not seem to you that you need to sketch things out ahead of time.
04:47But from personal experience, I can assure you that taking the time to diagram
04:52your relationships during the planning stage will require a lot less work than
04:56doing so after you've already begun your programming.
Collapse this transcript
2. Resolving Many-to-Many Relationship
Understanding problems caused by many-to-many relationships
00:00Earlier our discussion on identifying relationships, I mentioned that you could
00:03potentially identify a many-to-many relationship during your data modeling and
00:08that when you do you should resolve them by adding a join table, which we will
00:11discuss in our next movie.
00:13However, I'm frequently asked why many-to-many relationships need to be resolved at all.
00:17After all, FileMaker lets you create them, and they appear to work, at least up to a point.
00:21So I am going to show you some examples of where a many-to-many-related
00:24structure would break down inside of a real FileMaker database.
00:27In the file that I have got here, if you open it up, you'll see that we have two
00:33tables, an Actors table and a Movie table.
00:38In the Actor table one record represents any individual actor and we've got
00:42unique IDs set up as a primary key field.
00:46In the Movie database one record represents one movie.
00:49Same thing here, primary key field to uniquely identify each movie.
00:53So what type of relationship might we have between these two tables?
00:57So consider the statement "one actor may act in many movies."
01:01So between the two tables one actor could appear in many movies, which on the
01:06surface appears that it's a one-to-many relationship.
01:09If this were in fact a one-to-many relationship, we could simply add a foreign
01:13key field, or Actor ID, to the Movie table and create a direct relationship
01:17between the two of them.
01:18For example, if we look at this movie record here, I've got an Actor ID field
01:23already on the layout, and let's say we determine that actor with the ID of 1, Boo
01:28Radley, appears in the movie Yet Another Sequel.
01:31Simple enough, I can just put their ID in there and now these two records are related.
01:36However, it's also true that one movie almost invariably involves many actors,
01:41so one movie could have many related actor records.
01:44So what you really have here are two one-to-many relationships crossing over
01:48between two tables and not a true one to many in either case.
01:52And it's not so obvious how to solve that problem using the structure that I
01:55proposed a moment ago. So, for example, this actor with the primary key of
02:00number 2 also appeared in yet another sequel.
02:03You'd think that you could simply put another number in this field or a comma
02:08and another number, but in this scenario the Actor ID field in the Movie entity--
02:13otherwise known as the foreign key in the proposed relationship--would have to
02:17have more than one value at once.
02:19The technical term for this is a multi-valued attribute, and most database
02:23designers will argue strongly against the use of multi-valued attributes,
02:27especially inside of a key field in a relationship.
02:29So these multi-valued attributes are a bad choice for creating
02:33many-to-many relationships. Why is that?
02:35Well, for example, it could be very difficult to create a FileMaker Pro
02:38subsummary report listing actors in their individual roles or even an account of
02:42all the roles that they had ever played
02:44if all you're doing is simply just adding comma-delimited numbers to a field
02:47inside of an Actor record.
02:49For example, what table would you use for a report like that?
02:52Our report would need to indicate one record per role that an actor has played
02:55in a movie, and we don't even have a table to support that.
02:59How could I create counts of actors inside of a movie, for example,
03:02manually count all the different IDs inside of a field, or even do
03:05something programmatically?
03:07This wouldn't necessarily be accurate as the number of actors in a
03:10movie continue to grow.
03:11You would need something more dynamic.
03:12Another issue, what about the fact that you might want to store a
03:16character name that the actor played in each role and maybe even the salary
03:20they received for doing so?
03:21These would actually be attributes, but attributes of what?
03:24Is a character name an attribute of a movie? No.
03:28Is a character that an actor played in a movie an attribute of an actor?
03:32Maybe if they have only appeared in one film, but what if they have appeared in multiple films?
03:36Many developers who aren't comfortable with how to properly resolve this issue,
03:39they then try to create multiple instances of the Actor ID in the movie record.
03:45Here is an example of that.
03:47This seems to easily accommodate the Actor with primary ID 1, Actor2, and we
03:53still have some room.
03:54And sure, in this case you could store various Actor IDs separately.
03:58However, this is still wrong.
03:59Now if you wanted to search for all the movies that Jaxson Caymus appeared in
04:03as an actor, you would have to do four different searches, one in each one of
04:06these fields, just to make sure that you're not missing one of the IDs because
04:10you don't know whether or not you've put his ID of 2 in Actor1, Actor2, Actor3, Actor4.
04:15You are not even sure which field to search upon.
04:18That alone should tell you that something is wrong.
04:20Also, what if one actor appeared in 50 films, or a movie had a hundred
04:24different actors in it?
04:25Are you going to create fifty or a hundred different films in your table
04:28just for that one actor in their own special layouts inside of your database?
04:32Plus then you would have to create fifty character name fields, as well as
04:35fifty salary fields.
04:37You should start to get the idea here that something is definitely wrong if you
04:40have gone down this path.
04:41In many database systems, FileMaker Pro included, you're much better off using a
04:46different strategy to resolve these types of relationships,
04:49and this strategy I am proposing is actually a very easy one.
04:51You simply create a third table that we call a join table, and we will discuss
04:55this approach in the next movie.
04:56By attempting to join two tables directly, you present issues where we
05:00can't find data properly,
05:02we can't report on it properly, or even view it efficiently.
05:05The modeling phase is a great place to find out that you have these issues
05:08because you are just doing it on a piece of paper with pencil marks at this
05:11point, rather than having to go through several hours of development inside your
05:14database before you discover that you have a many-to-many relationship and all
05:17of its corresponding issues.
05:19Eventually, you will.
05:20Instead, you would want to create a joint table to fix all these issues quickly
05:24and permanently within your solution.
Collapse this transcript
Adding a join table
00:00We have discussed the potential problems with leaving a many-to-many
00:03relationship in your database solution. And again, FileMaker allows many-to-many
00:07relationships, so why would we want to avoid them?
00:09To review, the issues that we mentioned in the actor movies many-to-many
00:13relationship were, that we wanted to create a report that lists all the actors,
00:17their roles, salary, and total salary for all the roles they have ever played,
00:21but we didn't have a context or a table to be able to base that off of.
00:25And also we have ran into issues with storing character names and salaries for
00:28each role, because again, no table exists for a role.
00:32And then also how do we manage actors working in different numbers of movies?
00:35One actor might be working on 10 movies,
00:38another working on five, and then those lists can constantly grow.
00:41So if we define a field for each one of those roles for the actors, we would
00:44never know how many different fields we would need.
00:47We also discussed the searching issues that we would run into in our database.
00:50How would we find an actor that played a certain role via search?
00:53In order to correct these issues, let's start first by looking at the tables.
00:57Our problem was identified when we determined that one actor can act in many
01:01movies but also that one movie can have many actors.
01:05Our rule is that all relationships need to be one-to-many relationships, not the
01:08many-to-many relationship that we see here.
01:11And really a many-to-many relationship is just two one-to-many relationships
01:16combined together into one.
01:17So to get just two one-to-many relationships then we will want to break the
01:21many-to-many relationship into two separate ones.
01:24First, let's get rid of the one relationship that we do have.
01:27Now to be able to create two more one-to-many relationships, we are going to
01:31need add another table to the mix, and this table we'll call roles.
01:34We could just call it actor movies, but in this case it can act as its own
01:38entity because it will have its own attributes, and we'll get to that in just a minute.
01:42After we add the new table, we can now create two one-to-many relationships to it.
01:47One actor can have many roles, so we make the actor the one and the roles the
01:51many, and one movie can have many roles,
01:54so we make movie the one and roles the many.
01:57Now we can have our original two one-to-many relationships and no more
02:00many-to-many relationship.
02:02So now that we have these two new relationships in place, let's look at how this
02:05opens up the door to solve our problems that we identified earlier.
02:08I am inside the exercise file 02_02, and you will see that I've already added
02:12the new roles table.
02:13If you look at File > Manage > Database, you will see that I have created the
02:18new table Roles where one record equals one actor in a movie, and I have
02:23created the appropriate key fields and even connected these relationships in
02:27the Relationship graph.
02:28This file is simply a preview of lessons that you will learn in more detail
02:31later in the title, like lessons on keys, portals, and related fields,
02:35but we are using it here to illustrate the benefits of a join table,
02:38so feel free to come back to this file after you watched the entire title to see
02:41how it's all put together.
02:42For now, just use it to follow along.
02:45So the first problem that we wanted to address was the problem that we have no
02:48table that had one record per actor in a movie.
02:51Well, creating the Roles table solved that for us.
02:54A record in the Roles table is an intersection between an actor and a movie, and
02:58they contain both an ActorID and the MovieID, but in addition they also can have
03:02their own attributes,
03:03for example, the character that that actor played in a movie and perhaps the
03:07salary that they received for portraying that character.
03:10You'll see that displayed here in a layout called Roles.
03:13You will also notice that this layout solves our second problem, storing
03:17character names and salaries for each role.
03:20Previous to this, no table existed for storing that information and now one does.
03:24So now each time an actor appears in a movie we simply create a role record, and
03:29then we can add character name and salary to that new role record that we
03:33created, and we can do this in unlimited number of times.
03:36So how ever many times an actor appears in a movie, we just create that
03:39number of role records.
03:41So now that we do have a table with roles, each with their own character name
03:44and salary, we can finally create this report that we intended to create in the first place.
03:48I have already created the report in this sample database
03:50if you want to take a look go under Actor Subsummary. This report has an actor
03:55and then dynamically lists the number of roles, no matter how many roles they
03:59have, and then even totals up the salary for each.
04:02This report would simply be impossible if we do not resolve our many-to-many
04:05relationship by adding a third table.
04:08This report also shows a solution to the last problem that we have with our
04:11many-to-many, how do we manage actors working on different numbers of movies?
04:15Well, we notice that the first actor, Boo Radley, has 10 roles, so does Jaxson Caymus.
04:21But the actor Francis Schrodinger only has six, yet this report doesn't have to
04:24show four blank fields for Francis.
04:27If we were to go with the strategy of simply defining a field in an Actor table
04:31every time an actor appeared in a movie, we would end up with empty blank spaces
04:35here in this report.
04:36If you navigate over to a layout called Actors, you will see another example of this.
04:42Here's the Boo Radley actor, and we are only taking up so much screen space to
04:46fill their 10 roles. Same thing with Jaxson Caymus and Francis Schrodinger.
04:51On this layout we used something called a portal, which allows us to see any
04:55number of related role records per actor, with a scrollbar here that you see on
04:59the right-hand side whenever the number of related records exceeds the space
05:03that's allotted on the screen.
05:05If we move under the old layout that we are working with, Multiple Actor Fields,
05:09we will see that using the old many-to-many strategy of defining a field every
05:14time a movie had an actor in it would not only require us to enter data twice
05:19for each time an actor is in a movie, but we would also have to go and define a
05:22field every time that they added a new movie to their resume.
05:25And that simply doesn't make sense, especially if they end up having 50, 60, or
05:29100 different movies that they are a part of.
05:31And then finally, our last issue:
05:33how do we find an actor that played a certain role via a search in FileMaker?
05:37Well, if you go into the Actors layout, we can enter Find mode and we can
05:43use these related layout objects, like a related field inside of a portal, to
05:47simply do a search.
05:50For example, if I wanted to find all the actors who played the character of
05:53Romeo, I could simply type that into the related Character field and perform a
05:58find and it comes back with just one record in the found set and tells me that
06:02the actor Boo Radley played that character.
06:04This again, would be impossible in the many-to-many relationship scenario.
06:09Additionally, I can also do a search for which actors appeared in a certain movie.
06:15I type in the movie name, and then it finds all three actors happened to
06:21appear in that film.
06:22Just a couple of different ways that you can use a proper relationship
06:25structure to isolate different found sets of data.
06:28Rather than just remembering the rule of having to eliminate a many-to-many
06:32relationship and add a third join table, think instead of the benefits you will
06:36receive by having this table in place, and at the same time you won't have to
06:39encounter the plethora of issues associated with many-to-many relationships.
Collapse this transcript
3. Introducing Key Fields
Using primary and foreign key fields
00:00Once you've completed your data-modeling exercise, you'll have determined what
00:03tables you're going to need in your FileMaker database, as well as what
00:06relationships are going to be needed between those tables.
00:09What you will need in order to create relationships is something that could link
00:12each related table together so that each table has to have a little hook in
00:16there that allows that connection.
00:19In relational databases you are going to connect two related tables together
00:22using special fields defined in each table, and these fields are called keys.
00:27A key field is just like any other field that you're defining in your database
00:30but unlike these other fields, they perform special functions.
00:33Key fields come in two different types and each type has its own function.
00:37There is the primary key and the foreign key and these are two more pieces of
00:41vocabulary that you are going to hear a lot in this title, so it's a good thing
00:44to understand what they are now.
00:46Let's look first at primary keys.
00:48A primary key is a field that gets defined in the table acting as the one in the
00:52one-to-many relationship, otherwise referred to as the parent table.
00:57Remember that there's always a parent table in a relationship and always a child table.
01:01Because our relationships are always going to one-to-many, the parent is the one
01:06and the child is the many.
01:07So the rule to follow when determining which tables need a primary key field is
01:11that we need to define the primary key field in every parent table.
01:15Primary key field's main purpose is to ensure the uniqueness of each record in
01:19this table, so they must contain a unique serialized value inside every record.
01:23These records must never be duplicated within a single table and each parent
01:28must have its own Primary Key field defined.
01:30Since any one relationship will be between two tables and we already determined
01:34that there needs to be a primary key field defined in each parent, then there is
01:38also needs to be a field defined in each child table so that these two related
01:41tables can be linked.
01:43The type of field defined in the child table is called a foreign key field.
01:47This is going to be used to link a child record or a record in a child table back
01:51to its parent record in the parent table.
01:53This is how we actually link the tables together or know how one record is
01:57related to any other records.
01:59The rule to remember for foreign keys is that each child table is going to have
02:02a foreign key field defined within it.
02:05However, these values do not need to be unique because anyone parent could have
02:09multiple related records in a child table.
02:12Understanding the concept of keys and the roles of primary and foreign keys
02:15specifically are critical to understanding how to link your related
02:19databases together.
02:20After you understand the two types of keys, you can then move on to identifying
02:24which of your tables need a primary or a foreign key.
Collapse this transcript
Determining which tables need keys
00:00We've discussed the concept of keys, both primary and foreign, and how they're
00:04critical to building relationships in your database.
00:07The next step is understanding which of your tables will need these key fields defined.
00:12Let's take a look at the ERD that we've been talking about so far in this title
00:15and determine what types of keys we'll need.
00:18In review, we have five tables, each with the relationships already defined.
00:24The primary key decisions are easy: every table acting as a parent needs a primary key.
00:30Let's look at which tables are acting as parents. So here we can see that
00:34companies are the parent to contacts, contacts are the parent to orders, orders
00:40are the parents to order products, and products are also acting as the parents to
00:44order products, and therefore all these need primary key fields.
00:49Now how do we determine which tables will require a foreign key field?
00:53Well, an easy rule to follow here is that every child table needs a foreign key,
00:59and if you notice, you can identify the child tables easily because they all
01:02have a double hash touching them.
01:05With this in mind, remember that each table that has a double hash touching it
01:10will require a foreign key field.
01:12Let's take a closer look at our example ERD to see which tables have double hash
01:16marks touching them.
01:18We can see that three tables have double hash marks.
01:23Contacts is the child to Companies, Orders are the child to Contacts, Order
01:31products are the child to both Products and Orders. But if we look closer at the
01:37Order/Products entity, we see that it has two sets of double hash marks,
01:41thus, it's acting as a child in two different relationships.
01:45Therefore it'll require two foreign key fields defined, one for products and
01:50one for orders. Looking at our diagram we see that some tables play different
01:56roles in different relationships. Some are parent tables in one relationship
02:01and child tables in others.
02:04The way that we keep all of the straight in our database is by defining the
02:08proper primary and foreign key fields.
02:11Determining which tables perform which roles will help you figure out which
02:14tables need primary keys and which are going to need foreign keys.
02:18And if you take the time to set these up before you start working in
02:21FileMaker Pro, it's going to save you tons of time creating relationships in
02:25your database.
Collapse this transcript
4. Using the FileMaker Relationship Graph
Defining tables
00:00In the data-modeling exercise, we determined that we needed four tables, one for each entity.
00:05In this case it was the Customer table, an Orders table, and a Products table.
00:10We also determined that we had a many to many relationship which required us to
00:14add a new join table that we're going to call the Order Line Item.
00:18So in this movie we're going to talk about how to add these four tables to your
00:21FileMaker database, and this is also the first time in the data-modeling process
00:25that you're actually opening up the FileMaker Pro application.
00:29So after opening up FileMaker Pro, you'll go to the File menu and select New Database.
00:34You'll see a dialog appear on screen, and FileMaker is asking you what you want
00:39to name your new file and where you want to save it.
00:42So we'll choose the Desktop and we'll leave the name Untitled.
00:45And once we've made those decisions, we can hit Save, and now you'll notice that
00:49it's created a FileMaker Pro database for us and taken us to the quick table
00:53view for our untitled layout, but we're not done with our table setup.
00:57So from here, let's go back into the File menu and we're going to pull up the
01:02File > Manage > Database window again, and we're going to concentrate over here
01:06on the tab for tables, since we can't create things like fields and relationships
01:11until we've already got our tables in place.
01:14And right now you'll see that we've got one table in our list, but it's called
01:17Untitled. So it's a good practice to name the tables in your database after the
01:22entities that they represent, so since we don't have any entities for untitled,
01:26why don't we rename this one Customer?
01:29So if we select the existing table names, you see we've highlighted, go down to
01:35the box next to table name and type in the word Customers. And instead of hitting
01:41the Create button, we're going to hit the Change button, and you'll see that
01:44that table has been changed to Customers.
01:46So now we have a table in our database that represents the Customers entity.
01:49And we have got three more entities that we need to represent as tables, so
01:54let's add those to our database.
01:56The next one will be Orders, and this time I'm going to hit Create, and it's
02:01created a new table for us, and we'll say Products. And I can either hit the
02:08Return key or click on Create and then finally OrderLineItem, our fourth and final table.
02:18So we've created one table in our database for each bucket of data that we
02:22discovered during our data-modeling exercise.
02:24FileMaker Pro has now created a table inside the database and one default layout
02:29for each table that we'll see in later exercises.
02:32Once we've created these tables, we can move on to creating things like fields,
02:36and in the case of having multiple related tables, we can now move on to
02:39creating relationships between these tables, but all of that begins first with
02:43creating the tables inside of our FileMaker database.
Collapse this transcript
Defining key fields
00:00In order to create relationships in FileMaker, you first need to determine which
00:03tables you're going to have in your database and then create those tables.
00:06As you'll see inside of our exercise files, if you go into the 04_02 files, and
00:13under the File > Manage > Database, you'll see that we've already got four
00:18tables created inside of our database.
00:20It's one table for each entity that we've identified throughout our
00:23data-modeling exercise.
00:25In that exercise, we identified that we had four different entities--
00:29Products, Orders, Customers, and OrderLineItem--and we've created a table
00:33for each of those here.
00:35By evaluating the one-to-many relationships between each of these tables, we
00:38determine that every child table in a one-to-many relationship which is on the
00:43many side will need to have a foreign key field and every parent, which is the
00:48one in the one-to-many, will need to have a primary key field defined.
00:52If we look at our relationships here, we see that we've got relationships
00:56between Products and OrderLineItems, and the products are the one and the
01:00OrderLineItems are the many.
01:02So the Products table is going to require a primary key field and the
01:05OrderLineItem table will require a foreign key field, in this case the
01:09Products ID foreign key.
01:11We also have a one-to-many relationship between Orders and OrderLineItems.
01:15So Orders being the parent will need a Order ID primary key field, and
01:19OrderLineItems being the child will require a Order ID foreign key field.
01:24Then finally, the last relationship is between Customers and Orders, where
01:28Customers is the one, or the parent, so we will need a Customer ID primary key field.
01:33And Orders acts as the child in this relationship,
01:36so it's going to need to have a Customer ID foreign key field defined.
01:40So this shows the roadmap of the primary and foreign key fields that we need to define.
01:45So let's move into FileMaker Pro and define those fields.
01:48You define key fields in the same way that you would define any other field.
01:52Inside of your Manage Database window, you'll notice that we're looking at the tables.
01:57All four of our tables are already defined.
01:59By double-clicking on one of these tables, it will take you over to the Fields
02:03tab inside the Manage Database window, and we currently don't have any fields
02:07defined, but we're going to go ahead and create these.
02:09I'm going to start with the Customer table where we need to define just one
02:12field, a primary key field.
02:14Before we define any fields in our database, we're going to need to decide what
02:18name we're going to give our field.
02:20For key fields it's a good practice to follow some naming conventions, so that
02:24later, you can easily identify the key fields in your database, as opposed to
02:27some of the other fields that represent attributes.
02:30There are various different naming conventions to use.
02:32None of them are right or wrong.
02:34But the convention that I like to use is to add a suffix to the field name that
02:37indicates what type of key that it is.
02:40So since these are primary keys, for example, I'd like to use pk as the suffix.
02:45I also like to have my key fields appear at the top of my field list when I
02:50sort them by field name,
02:52so I like to use a prefix of characters that will have them show up in the top
02:56of that sort order, and the ones that work for me are the underscore.
03:00So if I type in the single underscore, that will have this field show up at
03:03the top of my list.
03:04But I'll also have foreign key fields in some tables, and to make sure that
03:08primary keys show up above foreign keys, the naming convention I like to use is
03:13a double underscore followed by the name of the field.
03:17The name of the field that I like to use after the underscore is the name of the
03:21table with the letters ID after it, so we know it's a key.
03:25So in this case since we're in the Customer table, I'll call it Customer ID, and
03:30then I'll end it with the pk suffix, indicating that this is a primary key field.
03:33I'll also put some comments in here--
03:39Customers--and then we'll hit the Create button.
03:42Now the field has been created, but there are some additional options that we
03:45need to set up to make it act like a primary key field.
03:48Selecting the Options button, you'll see that it opens us up to the Auto-Enter
03:53tab option, and here what we want to do is ensure that the value inside this
03:56field is going to be unique and cannot be modified by any users.
04:00So first, in the Auto-Enter tab, there is an option inside of FileMaker called
04:04Serial Number which means that every time a new record is created, FileMaker
04:08will go and allocate a next value based on whatever you have in these two
04:12fields and increment that next value by whatever you put in this field here.
04:17So we simply just need a number that's unique, so we can leave the default
04:20next value one, increment by one in place, and each time FileMaker crates a
04:24record it's going to give it a new number, and it will ensure that those
04:28numbers are never a duplicate.
04:30In addition, we want to make sure that no users change these values, which would
04:33mess up all of our relationships between related records,
04:36so we'll hit Prohibit modification of value during data entry.
04:40We hit OK and now we've got our Customer ID primary key field defined to give
04:45us a unique value every time a record is created and not allow users to make those changes.
04:50If we go back to our ERD, we see that in addition to customers, we also
04:56have orders acting as a parent and products, so both of those tables will
05:00require primary key fields.
05:02So let's click on the dropdown menu to go over to Orders, and let's follow
05:07the same convention.
05:08__OrdersIDpk, give it a comment, "primary key for Orders," hit Create, check our
05:21options, and simply choose Serial Number, and Prohibit during data entry. Pretty simple.
05:28Now finally, one last time for Products, same thing,
05:31__ProductsIDpk, primary key for Products, choose Create, and hit Options,
05:44selecting Serial Number and Prohibit modification of value during data entry.
05:48So now we've got all of our primary keys in place, but we're still going to need
05:52to define our foreign keys.
05:54We see if we look at our entity relationship diagram that the OrderLineItem
05:59table has two foreign keys we need to define, and the Order table has one
06:03foreign key that we need to define.
06:04So let's start off with Orders.
06:06In the Order table we want to define a foreign key for the relationship between
06:11Customers and Orders, and instead of the double underscore in this field, I'm
06:15going to do a single underscore, because this is going to be a foreign key.
06:19When we name foreign key fields, I like to name them after the parent in the
06:23relationship that they're a part of.
06:25So in this case it's a relationship between customers and orders, so I'm going
06:29to name this foreign key field fk to indicate that it's a foreign key field.
06:33I'm going to enter in to the comment that this is a foreign key field for the
06:38Customers relationship and hit Create.
06:41Foreign key fields will have no options because we're going to use other
06:44mechanisms to populate these values and therefore create the relationship
06:47between the records.
06:48So for now we just want to name it using the single underscore, ID, and then the
06:53fk suffix as our convention.
06:58The only other table that acts as a child in the relationship is the
07:00OrderLineItem which is the foreign key field in the Orders in the
07:08OrderLineItem relationship.
07:10We hit Create and we have one more as well.
07:19The OrderLineItem also is a child to Products,
07:23so we will create the ProductsID foreign key and hit Create.
07:28And again, foreign key fields do not need any text options.
07:30These values will be populated manually or through some other mechanisms, not by
07:34the Auto-Enter options as in the case of primary keys.
07:38Now we have all our key fields. We can hit OK.
07:42Once you have your database created or the shell of the database created, you
07:46can start by adding things like fields, layouts, and relationships, and all of
07:49the different things that we'll cover in upcoming movies.
07:51Now, our next step is to create the links between these related tables now that
07:55we have our hooks, otherwise known as keys, already in place.
Collapse this transcript
Introducing the Relationship Graph
00:00At this point in the process of creating a related database in FileMaker we are
00:03assuming that you have already gone through the data-modeling exercise, got your
00:06tables determined and defined, and also gone into your database and defined all
00:11of your primary and foreign key fields.
00:13If you open up your exercise files, you will see that we have got a file called 04_03.
00:19Opening up 04_03 and going into the Manage > Database option and you'll see that
00:27we've got our four tables defined, and double-clicking each table shows different
00:32fields that are defined.
00:33You can also use the dropdown list to show those field names, and you see that
00:38we've got all of our primary keys and our foreign keys defined within our table.
00:42Now you will notice that there's another tab on the far right here and that one
00:45is called Relationships.
00:47Go ahead and click on the Relationships tab, and what you are seeing here is your
00:50first glimpse of what's called the relationship graph. And inside this
00:54relationship graph is where we can establish the relationships between the
00:58tables and also manage them in the future.
01:00You will see that we have four different blocks, or squares, within this
01:03relationship diagram.
01:05Each one of these blocks is known as a table occurrence, and every time you
01:09define a table in FileMaker Pro over in the Tables tab FileMaker will
01:13automatically add a table occurrence to the relationship graph for you.
01:18It's important not to think of these occurrences as tables, because we are going
01:22to learn later in this title that a single table could be represented on the
01:25relationship graph by multiple table occurrences.
01:28We are not going to worry about that right now, but instead we are going to
01:30focus on there being one table occurrence per table defined in our database.
01:35Now our goal in this exercise is to create relationships between these tables.
01:39We have already got our key fields defined, and our goal here is to create
01:43relationships, and that's really the easy part, as far as the task inside the
01:46database is concerned, because to physically create these relationships inside
01:50of the FileMaker relationship graph doesn't really take much effort.
01:53You will just take your cursor and you will go into the parent table, in
01:57this case Customers.
01:59You'll click down on the field that you want to use as your primary key and you
02:03will notice that the cursor turns into a cursor with a little dumbbell below it,
02:06and as you drag outside of that box over to the table occurrence that's going to
02:12represent the child table, you will have to pick between the two fields.
02:15And this is why I like to use the naming convention that we've chosen for the
02:19foreign key fields because you will see, it's pretty obvious,
02:22you do CustomerID to CustomerID with the pk on the parent side, fk on the child side.
02:28So after you select the foreign key field in the relationship, you'll release
02:31your cursor, and you will see that FileMaker then isolates which of the two
02:36fields are your key fields in your relationship and it also draws a little line
02:41that looks like a single-to-triple hash crow's foot showing the crow's foot on
02:45the many side and the single on the parent side. So, real easy.
02:49Just click and drag between the different foreign keys. And we have made this an
02:52even easier task because of the names that we've chosen for our key fields.
02:56So as you see here, we've got Orders and OrderLineItem.
02:59We click on the primary key for Orders.
03:02Deciding which of these key fields is going to be the foreign key in this
03:05relationship is pretty easy, because it's got the similar name to the
03:08primary key fields.
03:09We will go OrdersIDpk to OrdersIDfk.
03:14FileMaker adjust that and shows that primary key field and foreign ID key field isolated.
03:20And then finally, the last one, the ProductID, very simple, ProductIDpk to ProductIDfk.
03:29So not only are your table occurrences visually linked within the database, but
03:33now FileMaker has actually created relationships between these tables and also
03:38identified the specific fields defined within the tables as the key fields to
03:42link those tables together.
03:43So once you have gone through this process that we have just done here, you can
03:47then move on to start defining other things inside of your database.
03:50Later in this title I am going to show you the various different ways that you
03:53can use the relationships that we have set up here.
03:56All the different relationships that you are managing inside of FileMaker are
03:59all done through the Relationships tab.
Collapse this transcript
5. Working with Relationships
Understanding related fields
00:00We've been talking a lot about creating relationships between a parent and child
00:04table, but for the rest of this title we're going to talk about the many things
00:07you can do inside of your database once those relationships are in place.
00:10One of the primary benefits behind the concept of relational databases is to
00:14reduce redundancy and even borrow data from other related tables.
00:18For example, in this file that I've got on my Orders layout, if I go into Layout
00:23mode, I can see that this relationship has what I like to call the context.
00:29And let me explain that further by clicking on the Modify Layout button.
00:33And you'll see the first thing that we notice on any layout in the Layout Setup
00:37dialog is the name of the layout, which is immediately followed by the table
00:41that it's based on.
00:43That means that the Orders layout has the context of the Orders table.
00:47Another way to look at this is under the File > Manage > Database option, over
00:53in the Relationships tab.
00:54You should always remember that at any given point when a user is in your
00:58database, they're in the context of one of the tables on your
01:01relationship graph.
01:03So in the case of the Orders layout, we are in the context of the Orders table.
01:08And this is relevant when you're working with any kind of related fields or
01:11related layout objects on your layout.
01:14You'll have to know what you're looking at and from where you're looking at those.
01:17So, for example, if I have a layout that is based on the Orders table and I want
01:21to display data from Customers, I know that I them in the context of Orders,
01:25which is the child of the Customers table.
01:28Let me show you how that's relevant. Let's hit OK.
01:31So let's look at this concept in action back in the Orders layout.
01:34You'll notice that we already have several fields on this layout. Some of them
01:37are showing field names and some of them aren't.
01:40Ones that are showing field names, if we click on them, we'll see over in our
01:44Inspector which is on right-hand side that we are displaying data from the
01:49Orders table and it's a field called Sale Date.
01:52So these are all fields that have the same context as the layout.
01:56Your field is defined inside the Orders table.
02:00In some of these cases though, we don't have fields yet.
02:03So we'll look at Email, Company, Address, City, State, ZIP. All of this entire
02:07cluster of fields, that's actually data that describes the customer for this
02:12order, not the order itself.
02:14So these are fields that are actually already defined over in our Customer table.
02:19So in order to have this information displayed on our Orders layout and anything
02:23that we print off based on this layout,
02:25we can do one of two things.
02:26We can define these fields inside of Order, but then we would have two different
02:31places where the Company, Address, City, State, ZIP is being stored inside of
02:35our database, which would present a redundancy issue.
02:39For example, if I have a Company field defined inside Order and inside the
02:44Customer table--if we look, we already have one defined in the Customer table--
02:48if I define it in two different places then I have to manage the data inside
02:54that field in two different places, which could create a lot of error and have
02:57some inconsistencies in the data.
02:59So instead what we're going to do is take advantage of the fact that the
03:02Orders table, from which this layout is based off of, is related to the Customers table.
03:07And what we're going to do there, because they're related, is we're going to
03:09borrow the fields from the other table, thus having the data only stored in one
03:14place but displayed wherever we need it to be displayed.
03:17So let's take a look at that a little bit closer here.
03:19So concentrating on this Email field, this is actually the email of the customer
03:24for which this order belongs.
03:25So if we look over here in the Inspector, we don't have any data being displayed.
03:29So if I click on the little Edit icon, it will allow me to specify a field.
03:33So any time you add a field to a layout, you'll notice that you've got the
03:36option to pick fields from the same table that the layout is based on,
03:41in this case, Orders.
03:42But what you might not know is if you click on this little dropdown here, you
03:45see that you can pick from fields that are from related tables,
03:49in this case, Customers.
03:51So if I choose Customers, you'll notice that on the left-hand side they all
03:54have a double colon which indicates that they're what is called a related field.
03:58And here if I select Email and hit OK,
04:02now we've got a related field, a field that actually lives inside of the
04:06Customer table but is placed on a layout inside of the Orders table.
04:09So it's a related field, but how are these two records related?
04:12We do have a relationship between Customers and Orders where Customers is the
04:16parent and Orders is the child,
04:18but how are the actual records related?
04:20Well, we've got a field here.
04:21You see this as our foreign key field, and of course, we know that two
04:25records will be related when the value inside the foreign key matches a value
04:29inside a parent key.
04:30So what needs to happen in order for these related fields to show data?
04:34Well, we need to populate the foreign key value with a valid primary key
04:39from the Customer table.
04:41And the way that I've set that up, here we have the foreign key value.
04:44If you look at the field, I've got a Pop-up menu assigned, and I've put a value
04:50list on the pop-up menu.
04:51And this is a pretty common technique, so I'm going to show you how I've got this set up.
04:54If you click on the Edit icon,
04:56you'll notice that I have a value list set up in the database already, and what
05:01it's doing is showing me all the values from the CustomerID primary key field
05:07back in the parent table of Customers.
05:10So that way I'm choosing from only valid primary key values, and I'm populating
05:14the foreign key field, thus making these two records related.
05:17Now, since users could look at a list of primary keys and not even know what
05:21customer they're associated with, I've gone with the option to display values
05:25from the second field as well.
05:26So let's look at what that looks like in Browse mode.
05:29Again, a very common technique.
05:31We'll go into Browse mode.
05:34After saving your changes, you'll see now I have a dropdown list of all the
05:37valid customer records with all their primary key values, thus allowing me to
05:41choose a valid CustomerIDpk value to place inside of the foreign key field.
05:48This is a common method for linking a child record to a valid parent.
05:51And you see in Browse mode if we choose one of these options, we see now that
05:55our related Email field populates.
05:58That's because it knows which customer record to go grab the email data from.
06:02You'll see that changes depending on which one of these values we select.
06:07So this is a great way to show related data without having to duplicate related
06:12data on an order record.
06:13And as the result, we see in email address on the order record, even though the
06:17email address data actually lives and is stored inside the Customer table.
06:21Back in Layout mode, we see that there's a double colon there, and we can add
06:27all the other related fields as necessary.
06:29Pull down to Customers, and in this case we're looking for Company.
06:34See that shows up with the double colons in front, indicating related fields.
06:37Let's go again from the Customer table.
06:40What you would likely do is drop them on the layout as a related field in the
06:47first place, but here we had some placeholder fields, and I will choose these
06:53other options for you.
06:54So, now all of the fields that we see here with the double colons in front of
07:08them are related customer fields that we are borrowing from the parent table.
07:14So I like to call this technique borrowing from your parent.
07:16And if we go back into Browse mode and save our changes, we'll see that they
07:21will all update every time we pick a new value to put inside of our foreign key field.
07:28So, why does this work?
07:29How do we know that this is the correct data in these fields?
07:31Well, this works because the Order table is the child, or the many, table in the
07:35relationship between Customers and Orders.
07:38This means that any given order record will only ever have one valid related
07:42parent customer record.
07:44So that way, since only one piece of data can fit inside of a FileMaker field,
07:48we know that it will have the correct value showing in these related fields
07:51because we only ever have one related customer record to pull data from.
07:55So that way we can rely on this data after populating the foreign key field and
08:00know that it is correct and it is in fact the data that's coming from the proper
08:03customer parent record.
08:06Since a field in FileMaker can only store one value, we know that we will have
08:09the correct value showing in these related fields because there were only ever
08:13be one related customer record to pull data from, and not only that, there's a
08:17persistent connection between this data.
08:19So, for example, if I look at this related piece of data and I go into it and
08:24I update it, and now if I go into the Customer record and do a search for
08:30Orthopedic Specialists, you'll see that the data has been updated on the parent record as well.
08:38So if I change it back to St.
08:42and go back into Orders, we'll see that it's updated.
08:45So this way I can change a piece of data when I'm looking at it inside the
08:49context of Orders and it will update the parent when necessary.
08:52So again, I like to call this technique borrowing from the parent.
08:55It's an easy term to remember, and it reminds us how we can use related parent
08:59fields in a layout with the context of a child table, allowing us to reuse
09:03related parent data without having to double enter and to also have it
09:07faithfully update when the parent record is updated.
Collapse this transcript
Understanding portals
00:00One of the primary benefits of relating tables together is the ability to share
00:03live data between them.
00:05We've already looked at how we can place related fields on a layout so that a
00:09child table can borrow values from any related parent table.
00:13This of course eliminates the need for redundant data inside your database.
00:17But thus far we've only been looking at using related fields on a layout that
00:20has the context of the child table in a relationship.
00:24If we look at the relationships that we have in our database by going under the
00:29File > Manage > Database and choosing the Relationships tab, we will see that
00:33here's the Orders Table.
00:34That's the table that this layout is based off of. And we've placed some related
00:39fields that we are borrowing from the parent table of Customers, but we also see
00:44that Orders has a relationship down to OrderLineItems.
00:47So what we want to do now is put some related fields from the
00:50OrderLineItems table on here.
00:51You notice that we've already got a section for this in our layout.
00:54We've got some text headers for the different columns: Product ID, Product Name,
00:58Part Number, and so on.
01:00So why don't we place some related fields from OrderLineItems below each one of those columns?
01:05I will go under Insert > Field, and I'll want to make sure that I am choosing from
01:11the dropdown list here OrderLineItem.
01:13You see that that's selected, and so now what I am doing is I am choosing from
01:17fields that are inside the child table.
01:20So Orders is the parent to OrderLineItems, so I am picking a field--let's say the
01:25ID field. And we don't have to choose the label, make that a little bit smaller.
01:33And let's do one more underneath Product Name,
01:35Insert > Field and we will go to Product Name.
01:42So now just like we have got related fields from the parent table to Orders,
01:47which is Customers, we have now got related fields from the child table to
01:52Orders which is OrderLineItems.
01:53So let's go into Browse mode, and see what we get.
01:56Well, we have got some data showing up, but it's only one product.
02:01So what happens if we have more than one line item on this order?
02:04Should we add some new fields?
02:06Copy the same fields?
02:08Actually no, neither of those will work.
02:10The problem here is, what we are seeing is that the Order Table is the one, or
02:14the parent in the relationship between Orders and OrderLineItems,
02:17so that means that there can potentially be many related line item records to this order.
02:22Since a FileMaker field can only display one value at a time, we won't be able
02:27to use a related field. It would always appear that we only have one related record, and that's just
02:32simply not reliable.
02:33Instead, what we could really use is some type of a field or layout
02:37object that would display a dynamic list of related child records,
02:41regardless of how many there were.
02:42Well, we actually do have a special kind of layout object in FileMaker and
02:46it's called a Portal.
02:47Let's go into Layout mode, and I will show you how we use a portal.
02:52First, let's get rid of our first attempt.
02:56Now, look at our tools in the status toolbar on the top of the page.
02:59You will notice that there is one right here that's called the Portal tool and
03:04when you click on this option, like in many other layout objects, you will see that
03:08our cursor turns to a crosshair.
03:09So what I want to do is draw a box about this size to make sure that it fills up
03:16all the area below those different column headers.
03:18So when I release it, we see a window pop up that's called the Portal Setup.
03:22We also see that in the layout we've got what appear to be multiple rows.
03:26So really, this is kind of like having one related field, but the field will
03:30then repeat itself for every related record that it has.
03:33This is really what we are looking for.
03:35Instead of using related field, we are going to use this Portal Layout object.
03:38So that way, if we have ten different related line items on one order, this will
03:42show ten different records;
03:43but if we only have two on another order, it will only show two different records.
03:46This is exactly what we are looking for.
03:47Now inside the Portal Setup, we do have some decisions to make.
03:51You will notice the dropdown that's very similar to the one that you see when
03:54you're inserting a field.
03:55This shows you the related tables that you can choose from, because a portal
03:59is only used in related tables, and I should clarify at this point, you will
04:03only use a portal on a layout that has a context of the parent in a
04:07relationship, because what it's used to do is show child records inside the
04:11context of that parent layout.
04:13Since we are in a layout that's based on the Order table, we know that the
04:17OrderLineItem is a child to the Order table, so we will select that option.
04:21We also have a couple of other Portal Setup options that we will get to in
04:25later movies, but I'm going to show one here that's called the Show vertical scrollbar option.
04:29What that will do is show a vertical scrollbar on the right-hand side of our portal.
04:34So even though we've only got four different rows here, if we end up with 30,
04:38the user can just scroll through.
04:39That way we don't have to take up all that space on the layout.
04:42So let's hit OK. And now the next window is asking us what related fields we
04:46want to put on there.
04:47Since each of these rows in the portal is going to be like a related record,
04:52what we're really doing is choosing the fields that are going to show up on each record.
04:56We're going to pick fields that are going to match the column headers that are
04:58already on the layout.
04:59So first, we've got Product ID and Product Name.
05:02Now, Product ID and Product Name are actually fields that come from the Product table.
05:07This portal row will have the context of OrderLineItem, which is related to
05:12products, so therefore we can borrow from the parent in that case as well.
05:16You'll see by simply clicking down to the Products option allows us to choose
05:20from all the related product fields.
05:23So let's choose the Product ID first and click Move and move that over--
05:28these are all the fields that are going to appear on this Portal row--and let's
05:31also choose Product Name.
05:35So the reason this will work, the Portal row has the context of
05:37OrderLineItem, but any one OrderLineItem record only has one related product
05:42record as a parent.
05:43So, that way we will only get one piece of data in each of these fields, and
05:46that's exactly what we are looking for.
05:48So we've got Part Number, moving Part Number over, and a couple of more,
05:53Taxable, same thing here.
05:55But now, Quantity is specific to the OrderLineItem record.
05:59So let's go back to OrderLineItem and choose Quantity.
06:05You can see by the prefixes that we've got Products, Products, Products,
06:09Products, and then OrderLineItem.
06:10These are the tables where we've defined those different fields. And we
06:14will finish up by adding price and extended price, which both come from the OrderLineItem.
06:20So we have got Products fields and OrderLineItem fields.
06:23The Products fields are being borrowed from the parent of the OrderLineItem, and
06:27the OrderLineItem values are coming from the actual OrderLineItem record that we
06:30are seeing inside the portal.
06:32So now when we hit OK, we notice that we have got a vertical scrollbar and we
06:36notice that only the first row, which was the only white row--the rest of them
06:39are gray in color when we are looking at them--
06:42we notice that that row is populated with all the related fields.
06:45You only have to fit the related fields into the first row of a portal for
06:49them to show up, and then when you look at it in Browse mode it will repeat
06:52itself for all the different related values.
06:54You also need to make sure to keep your fields within that first row, because
06:57they if bleed over into another row or outside of the portal, they are no longer
07:01considered part of the portal and that could mess up your layout.
07:04If you need more space, you can just grab one of the handles and make the portal
07:07larger, but we seem to have the right size here.
07:10Let's go into Browse mode, saving our changes, and take a look at what we've got.
07:15Now, it's no magic here.
07:16The exercise file that I am using happens to already have related data showing
07:21up in it so that we can display the related values properly.
07:24So what we see here as we go through each order is that the amount of
07:28related records changes.
07:30Some orders don't have any related records, some only have four or five, and
07:35then some have many of them, which we can see by scrolling through the portal
07:39using the vertical scrollbar.
07:41So as you go from record to record, all related child records will
07:45appear dynamically.
07:47Portals will help you most when you're designing layouts that are based on a
07:50parent table in a relationship.
07:52It provides extremely useful visibility of child records from the context of a
07:56parent, and it's going to be something that you are going to use on almost every
07:59database solution that you create.
Collapse this transcript
Using relationship options to create related fields
00:00Up until this point, we've been looking at how to use the FileMaker relationship
00:03graph to set up your database's basic one-to-many relationships.
00:07That relationship graph can be found under File > Manage > Database, and it's
00:12the last tab on the right.
00:14Relationships can have different options set up for each, besides just which key
00:18fields are used in the match tables.
00:20So you see now we've just simply selected what the primary key and the foreign
00:23key are going to be in each relationship.
00:25But if you'll notice, there is a little equal sign in the middle of line in
00:28between each tables in a relationship and if you click on that equals sign,
00:32you'll see the Edit Relationship dialog appear.
00:35This dialog lets us control all of the options for a relationship.
00:38You'll notice that each table in the relationship is represented here:
00:42one table on the left, in this case the parent, and then another table on the right.
00:47So this is where you can select all the different fields that you would use
00:50as your match fields.
00:51We've already got those selected because we've dragged and dropped between the
00:55primary and the foreign keys when we first set these up. This shows what our
00:58selections were at that time.
01:00Below the match fields are a series of options for each side of the relationship.
01:04There are options for records, created, or deleted or sorted on the parent
01:09side, and then there are options for records that are created, deleted, or
01:13sorted on the child side.
01:15So in this example what we're going to do is select one of these options on the
01:19child side, or the OrderLineItem side of the relationship, specifically
01:23selecting Allow creation of records in this table via relationship.
01:28This means that we can now use objects that refer to this relationship to create
01:32related records in the OrderLineItem table.
01:35Some of these objects could be a related field or more commonly, it would be a
01:39portal layout object.
01:40So when I close this window and go back to the Order layout, you'll see that in
01:47a portal that's based on the OrderLineItems layout, you'll see that when I
01:51scroll down to the last row, I have what appears to be a blank record.
01:55Well, what this is is a data entry record allowing me to create related
01:59OrderLineItem records through the context of this order layout.
02:04So this is just there for the user to be able to enter in their own data.
02:07If we go back into Layout mode,
02:09you see that I've also assigned a dropdown menu to the Product ID field.
02:15You can see over here underneath the Data tab we've got the Product ID field
02:19from the OrderLineItem and I've got a Pop-up menu selected, and here I've created
02:24another one of these value lists-- we can see it by clicking the Edit button.
02:28This value list is called ProductIDs, and what it's showing me is a list of all
02:33of the valid Product ID primary key values, and I've chosen the Product Name to
02:37show up next to it to help the user select the correct one.
02:41So in order to create a related value, users will populate the Product ID
02:45foreign key field with a valid primary key value, and then they can enter in
02:50the rest of the values.
02:50Let's look at that in action.
02:52So I scroll down to the very last row, click into the field, pick one of the
02:58products, and now a new related record has been created.
03:03I'll scroll all the way down to the bottom, and we see that I can enter in a quantity
03:08for my new value, or I can change an existing quantity.
03:12So by simply going into the Options in our Edit Relationship dialog, I've now
03:17added this ability to create related records through a portal.
03:20This is a great way to allow your users to do data entry for related records
03:23without having to bounce around to various different layouts in your database.
03:27If we go back under the File menu, to Manage > Database and into our
03:31Relationship Graph, double-clicking on the equals sign again, we notice that
03:36we've got a couple of other options.
03:38We've got Delete related records in this table when a record is deleted in the other table.
03:42What that means in English is that this will delete any related child records
03:47in the OrderLineItem table whenever their related parent order record is also deleted.
03:52This is intended to help you keep your data clean, but it should also be used
03:56with extreme caution, because it will delete all these child records in every
03:59case where the parent is deleted.
04:01So if you are cleaning out a test version of a database, and you delete all of
04:05the order records, all of your OrderLineItem records will be deleted
04:08automatically as well. So use that with caution.
04:11Finally though, you notice that we've got the option to sort the values.
04:14So not only will it sort records that we see inside of a portal, but anywhere
04:18else that an array or a list of related records are showing up.
04:21We'll look at this a bit further in a later movie.
04:24The FileMaker relationship graph allows you to not only create your one-to-many
04:28relationships, but it also gives you various different options for those
04:30relationships once they're already in place.
Collapse this transcript
Using multiple match fields in one relationship
00:00Once you have your main FileMaker table relationships in place, you'll have the
00:03architecture you need to build upon for your database.
00:06Now I'd like to discuss with you how you can also use the FileMaker relationship
00:10graph to create other query types of relationships that can be used for
00:13specialized purposes.
00:14Let's take a look at the relationship graph under File > Manage > Database, go
00:20into the third tab for Relationships.
00:22The first thing I want to point out is that the boxes that you place on the
00:25relationship graph are not actually tables, although they do look like them;
00:29rather they're known as table occurrences,
00:32sometimes also referred to as TOs.
00:34A table occurrence is exactly that,
00:36it's an occurrence, or an instance, of a database table in a relationship graph.
00:40Each table occurrence has a window, or a point of view, into the underlying source
00:44table, and therefore refers to only one single underlying source table.
00:49So each box that you see on screen references one of the tables in your
00:53database, and only one.
00:55However, one of the more powerful features of the relationship graph is the
00:59ability to create more than one table occurrence per table in your database.
01:03This way each new table occurrence, which actually represents a new relationship,
01:07in your database can have its own properties, separate from the original
01:11one-to-many relationships that you initially set up.
01:14I like to refer to these types of relationships as query relationships.
01:18Let's look at a couple specific examples.
01:20Back in Browse mode, you'll see on the Customer layout that I've got a tab here
01:25for Orders and I've already got a portal in place, which is going to display all
01:30of the orders related to this customer.
01:33And you'll notice that I've put some headers here for other related values.
01:37Here we'd like to see all shipped orders, and then here we'd like to see all future orders.
01:42So if I want to see portals under each of those, I could certainly take the
01:46portal that we have here and go change the criteria under the Edit Relationship
01:49dialog, but we want to preserve the original ALL Orders portal,
01:54so in that case what we're going to want to do is create new relationships.
01:58More specifically, we're going to create two new relationships.
02:01One relationship is going to show all orders related to a customer but only the
02:05ones that have a status of shipped,
02:08and the other one is going to show all orders related to a customer but only
02:12with a sale date that is in the future.
02:15So let's create those relationships now.
02:17I'll go into the File > Manage > Database.
02:21Before we go to the Relationships tab to set up this new table occurrence, let's
02:24look at the Fields tab, because I want to show you two fields that I created in
02:28the Customers table that we're going to use for these new relationships.
02:31Notice on the very bottom I've got two fields-- they're both calculations--
02:35one that's called Shipped.c and the other one that's called Today.c.
02:40They're calculations because I want one single value to appear in every
02:44one of the customer records.
02:45So in the Shipped.c field, I'm going to place the value Shipped in every single
02:51customer record in the database.
02:53I'm doing the same thing here in the Today.c Calculation, but instead, I'm using
02:57a calculation function to display the current date in every customer record.
03:01And I'll show you why I've done this in just a second.
03:04Let's move over to the Relationships tab, and now we see our four base tables, or
03:08table occurrences, that are based on our original one-to-many relationships.
03:12Now we can create a new table occurrence, and this one will be just for setting
03:16up the specialized portal.
03:18The way you add a new table occurrence to a relationship graph is by going
03:21to the far bottom-left corner and choosing the little table with the plus sign icon.
03:27Once you select that, you'll see the Specify Table dialog appear.
03:30So the first choice we need to make is, what table will this new table
03:35occurrence be based on?
03:36So in our exercise, we want to show all related orders as they're related to the
03:40active customer record, so we're going to choose the Orders table.
03:44After I select the Orders table, you see that a name appears below for a table occurrence.
03:50Automatically, FileMaker has given it the name Orders 2, and the reason for the
03:54number 2 there is because there already is a table occurrence that's called
03:58Orders, and you cannot have two table occurrences with the same name.
04:02I like to use my own naming convention when I'm naming table occurrences,
04:05because eventually, you're going to have a ton of these inside your
04:07relationship graph.
04:09And when you're looking at different places in FileMaker that reference these
04:11relationships that you've set up, for example, like dropdown menus and insert
04:15fields or dropdown menus when you're setting up a portal, it'll then be easier
04:19for you to pick the right relationship because of the name that you've given to
04:22the table occurrence.
04:24Since each table occurrence must bear a unique name to avoid FileMaker
04:27getting confused when you refer to a relationship, I like to use the
04:31following naming convention.
04:33I like to show the context for where we are starting, or the context of the table
04:37where we're going to be using this relationship.
04:39And in this case, it's customers, so I'll put in the word customers
04:43deliberately in lowercase.
04:45I'll follow that by an underscore, where I will deliberately put in uppercase the
04:51name of the table that this table occurrence is based on.
04:54And then finally, because this relationship will have a specialized purpose, I'm
04:57going to put an underscore here and put the word shipped underneath it.
05:01So this tells me just by looking at it that I'm going to use this in the context
05:04of Customers, but it's going to be based on related records from Orders, but I'm
05:09only going to be looking at related orders that have shipped.
05:11So now I hit OK, and you see it's created a new table occurrence.
05:15Both of these happen to be based on Orders.
05:18What I like to do in my relationship graph to avoid confusion is to select any
05:23new table occurrences that aren't part of the original one-to-many
05:26relationships and I like to assign them a different color,
05:29by clicking down on the Color Wheel in the bottom portion of the layout.
05:33I'll pick a nice red color.
05:35And that way I know that this is a specialized table occurrence, or a
05:37query relationship.
05:39So now let's create our link between Customers and Orders.
05:42And since we want to see only orders related to a customer, we'll start with the
05:46same primary key to foreign key match fields that we have in this relationship.
05:50We'll do customerIDpk to customerIDfk.
05:54Currently, these two relationships have the exact same properties, but we're
05:57going to add some additional options to this relationship.
06:00And the way that we do that is by double-clicking on the equal sign to invoke
06:04the Edit Relationship dialog window.
06:06So we've already established in this relationship that we want to see any order
06:10records that are related to the active customer.
06:12But in this activity, we want to see only those related order records that have
06:16a shipping status of Shipped.
06:19So there's a field over in the Orders table that's called Shipping Status, and
06:25the only ones that we want to show up in this relationship, or to be related via
06:29this relationship, are ones that have the value of Shipped.
06:33So I'll select this field as one of the match fields on the right-hand side, or
06:37in the Order side on the child table.
06:39But what I need is a field on the Customer table that is always going to have
06:44the value of Shipped in every record,
06:45and that's this Calculation field that we set up before this exercise.
06:49So now I've got Shipped.c to Shipment Status, and you'll notice that I have
06:54these buttons Add and Change.
06:55If I hit the Add button, you'll notice something pretty interesting is happening here.
06:59Now I've got two sets of match fields,
07:01two different pairs of match fields.
07:03To tell you what's happening here is this is going to show us any customer
07:07record where the value inside the foreign key field for CustomerID matches the
07:12active CustomerIDpk value--
07:14so basically, any order records related to a customer--but only the order records
07:19where the Shipment Status matches the value inside the Shipped.c field.
07:23And since every record in the Customer table is going to say the word Shipped
07:27then what we have here is show me all of my related records that only have the
07:31Shipment Status of Shipped, which is just what we need.
07:33So let's put this to work.
07:35We'll hit OK and hit OK again.
07:37Let's go into Layout mode to add a new portal.
07:40I'll make this easy, and we're going to select the existing portal and copy it
07:49and hit Paste, and this will allow us to have the same format.
07:54But now we've got two portals with the same relationship, so what we want to do
07:58is double-click on this portal, and this brings up the Portal Setup dialog, which
08:01will allow us to switch from the original Orders relationship that you see
08:05listed here, to the new one we just created, which is customer_ORDERS_shipped.
08:10So now in the Related Tables list, we see not only the actual related tables,
08:14but any table occurrences that are based on those related tables.
08:17So now we say customers_ORDERS_shipped, and these fields, if you look over here
08:22in the Inspector, they are all still using related values from Orders,
08:27so we want to make sure that the portal and the related fields in the portal all match.
08:33I'll simply double-click these and switch them quickly over to the new relationship
08:41that we just created.
08:42And let's see what this looks like in Browse mode.
08:45Saving our changes.
08:46Now we'll notice that here are all the different orders related to this
08:51customer, but here are all the orders related to this customer that have
08:54the status of Shipped.
08:55Let's try this one more time to fulfill the all future orders.
09:00This time we'll create another table occurrence, base it on Orders.
09:05We use the similar naming convention, but this time we'll say
09:08customers_ORDERS_future and hit OK.
09:13Here's our new table occurrence.
09:15I'm going to make this a different color, so I know that it's not one of our
09:18original base tables, and we can drag it to make it a little bit larger to see this.
09:23Now, let's create a relationship between customers.
09:25We do want to see any order records related to a customer, so we'll pick
09:29customerIDpk, customerIDfk, and now let's add some more criteria by
09:34double-clicking on the equal sign.
09:36And what we want to do is only show records that are in the future.
09:40So what I've got is a field on the left-hand side or the parent side
09:44that is a calculated field called Today.
09:47And inside that is going to be the current calendar date being pulled from the
09:50computer's operating system.
09:52We want that to match up with the Sale Date field in the Order record, so here's
09:55Sale Date, and we're going to add this new criteria.
09:57So basically what this says is, give me all related order records to the
10:01active customer record, but only show me the ones where the value in Sale
10:05Date equals today's date.
10:06But that's not exactly what we want to do.
10:08This of course would only show order dates for the current day.
10:12What we intended to do in this exercise is to show any sale dates that were
10:15greater than today's date.
10:17So you'll notice for the first time we're going to use a different operator.
10:20We've got the Customer table and the Orders table, and so far we've only created
10:24relationships that have an equal sign in the middle.
10:26But what you may not know is that you've got all these different operators
10:29that you can use, and we've got one operator in particular that would be very
10:32useful for us here, because we want to see only related records where the sale
10:36date is greater than today,
10:38so let's choose the greater than sign and hit the Change button.
10:41So now you see we've got two sets of match fields--
10:43the primary key and the foreign key-- but then also a value that shows the
10:47current date in every record in the Customer table.
10:50So no matter which record you're on in the Customer table, it'll always show today's date.
10:53And a portal based on this relationship would only show us records where the
10:58value in Sale Date is greater than today's date.
11:01So let's take a look at this new relationship in action.
11:04I'll hit OK and OK and quickly go into Layout mode, select this portal
11:10again, paste it right here, and all we have to do in this case is change the
11:18relationship again.
11:19So we'll double-click on portal and pick future--
11:22you see that new one I added.
11:23And we'll do the same thing for the fields in the portal, all three of them.
11:35And now we'll go into Browse mode and look at the data that we've got for
11:39our finished product.
11:40So we've got this customer.
11:42Here's all of their orders, so we only have one match field criteria for that
11:46relationship that this portal is based off of.
11:48But now we have a specialized query relationship that we set up that shows not
11:52only their related orders but only related orders with the value of Shipped.
11:55And then we have a third one that is all the related orders with a Sale Date
12:00greater than today's current date.
12:02So FileMaker, being a relational database application, allows us to set up
12:07architecture for relating those tables together within our database.
12:10However, the true power of FileMaker comes when you start to use the
12:13relationship graph to create these customized query relationships for viewing
12:17and working with specialized sets of related data.
Collapse this transcript
6. Real-World Data Modeling Examples
Donations example
00:00So far we've learned about the basic relationship types and how to model
00:03relationships between tables. [00:00:5.16] However, we've only looked at one use case.
00:08But in this movie, we're going to use a real-world example to apply what we've learned.
00:13In review, data modeling breaks into three phases:
00:17First, you develop a list of entities or tables that belong in your data model.
00:21Next, determine and diagram the relationships between those tables.
00:26And third, review the diagram for correctness and consistency and possibly
00:30revisit steps one and two if necessary. Okay.
00:34Here's a process description for this example.
00:38Take a minute to read this through, making special note where you think you'll
00:41see potential entities.
00:43And when you're looking for entities in your description look for nouns.
00:47Go ahead and pause this video and finish reading.
00:50Using the nouns technique, we can identify our entities as events, members, and donations.
00:58Each of these entities are in fact different and discrete types of data, and
01:02each can be described differently from the others.
01:05Let's also make note of the phrase "donations that are made by more than one
01:09member at a time" for later reference.
01:11Identifying these entities tells us what tables we'll need to define in our database.
01:15These will then become our entity list.
01:19Identifying the tables is only half the task;
01:22we must then determine how they are related to each other.
01:24And this is where you want to create an Entity Relationship Diagram,
01:28otherwise known as an ERD.
01:31In ERDs, it's common to represent your entities as a box with an entity name inside of it.
01:37Next, we'll move on to exploring relationships between the entities, starting
01:41first with members and donations.
01:44We will questions formatted within the one-to-many logic that we've been using
01:48throughout this title.
01:50In this example, here are the questions we should ask.
01:54Can each member potentially have many donations? Yes.
01:58We actually see this in the description where there's a reference to donations
02:01made by their members.
02:03Now, can donations be made from one and only one member? No.
02:08In our process description, it also states "donations that are made by more than
02:12one member at a time."
02:13So what we have here is what we call a many-to-many relationship.
02:17And if you recall from previous movies, the way we resolve a many-to-many
02:22relationship is by adding a third join table to our diagram.
02:26We'll add a new join table to this diagram, and we'll call this
02:30one members/donations.
02:32When naming a join table, I like to combine the names of the two parents so that
02:36we know what type of table it is when we see it in our diagram.
02:39So we'll visually represent the relationship between each parent and child table
02:43with a line connecting the two boxes.
02:46These lines will have a double hash on the members/donations side because that
02:49serves as the child in both of these relationships.
02:52Now let's look at the rest of the entities, and let's evaluate whether there's a
02:56relationship between donations and events.
03:00Now here the question we'll ask will be, is each donation associated with one
03:06and only one event?
03:07In this example, yes, donations can only be associated with a single event.
03:12Now, can each event potentially have many donations in the system?
03:16Again, our description mentions "a record of all donations generated by
03:20each event," so yes.
03:22This tells us that there is a one-to-many relationship between the two entities,
03:26with donations as the many.
03:28We'll want to represent that on our diagram as well.
03:33Now let's take a look at the entire diagram with all the relationships in place.
03:38The one thing to note here is that although the relationships are not drawn
03:41between members and events directly, these tables are still related through a
03:46chain of relationships.
03:48For example, a member could submit a donation when they're attending an event,
03:52and therefore that member is indirectly related to the event through this
03:56chain of relationships.
03:59Once our relationships are in place, we can now determine which tables need
04:02primary keys and which need foreign keys.
04:05We'll begin first with the primary keys.
04:07In review, we see the following tables acting as a one, or a parent, in
04:11their relationships.
04:13Members are a parent to members/donations and will require their own primary key.
04:18And donations are also a parent to members/donations and therefore need their primary key.
04:24And events are a parent to donations and thus will require a primary key as well.
04:29Now finally, the foreign keys.
04:31In review, we see that the following tables will be acting as a child or many
04:35in their relationship.
04:37Donations are a child to events, so they'll need an events foreign key, and
04:42member/donations are child to both members and donations,
04:46so we actually need two foreign keys in this table:
04:49one foreign key for donations and one for members.
04:52Going through all these steps in your planning stage will help you make sure
04:54that all of your relationships are one-to-many relationships.
04:57And it will also help you determine which keys you're going to need inside of each table.
05:02So that's a quick rundown of applying a relationship design to a
05:05nonprofit donations example.
05:07Feel free to use this structure if it maps to your situation.
Collapse this transcript
Class enrollment example
00:00In this movie we are going to use a real-world use case to apply what we've
00:04already learned about modeling relationships, but this time we're going to look
00:07at one-to-one relationships and instances.
00:11Remember, data modeling breaks down into three phases.
00:15First you develop a list of entities or tables that belong in the data model.
00:20Next, you determine and diagram the relationships between those entities, and
00:24finally, review the diagram for correctness and consistency--and sometimes
00:28you'll revisit steps 1 and 2 when necessary.
00:31Here's another process description.
00:34Remember, when looking for entities, we want to look for nouns in our description.
00:37So why don't you just go ahead and pause this video and take a minute to read this through?
00:43Using the nouns technique, we can identify entities as classes, teachers,
00:49students, and advisors.
00:52Each of these appeared to be different discrete types of data, and each can
00:56be described uniquely.
00:58Let's also make note of this section, "a teacher can also be an advisor"
01:02for later reference.
01:04Now we have our entity candidate lists, and these entities will eventually
01:09become tables defined in our database.
01:11But before they become tables in our database, we must first determine how the
01:14entities are related to each other.
01:17This is where we'll want to create an entity relationship diagram,
01:20otherwise known as an ERD.
01:23In any ERD, it's common to represent your entities as a box, with the
01:26entity name inside of it.
01:29Let's move on to exploring the relationships between these entities, starting
01:33first with students and classes.
01:35We are going to use questions format within the one-to-many logic that we've
01:38been discussing throughout this title.
01:40For example, here the questions would be, can each student potentially have many classes?
01:46Yes, we remember in our description, students can enroll in as many classes as they like.
01:52Now, can each class be taken by more than one student? Yes.
01:56We also learned that classes are intended to have more than one student in them at a time.
02:01So what we have here is a many-to-many relationship.
02:04And if you recall from previous movies, the way we resolve a many-to-many
02:08relationship is by adding a third join table.
02:11We will add a new table and call it Students/Classes.
02:16Now when I am naming a join table I like to combine the names of the two
02:19parents, but if you'd like, you can name them something different;
02:22in this case you can call it Enrollment as well.
02:25We'll then visually represent the relationships between each parent and child
02:29table with a line connecting each box.
02:32The double hash lines will be on the side of students and classes because that
02:36table serves as the many, or the child, in both of these relationships.
02:41Now let's evaluate whether or not there's a relationship between teachers and classes.
02:46Here are the questions we would ask in this case.
02:48Can each teacher potentially teach many classes? Yes.
02:52If you see in our description, it mentions teachers can teach many classes.
02:55Can a class be taught by more than one teacher? No.
02:59Class only requires one teacher.
03:02So this tells us that there is a one-to-many relationship between these two
03:05entities, with classes as the many.
03:09We'll want to represent this on our diagram.
03:12Now in this example system we have got something of the bit different happening.
03:16Let's look at the relationship between teachers and advisors.
03:20Now let's ask, can one teacher have many advisors?
03:24Well, this doesn't fit, because in this process description we saw a teacher
03:28can also be an advisor, so what we really have here is what's called a
03:32one-to-one relationship.
03:34What that means is that a teacher and an advisor are technically the same table;
03:38therefore, we'll want to eliminate advisors as a table on a diagram.
03:43But there is a relationship between students and advisors.
03:46We saw in our description that a teacher can be an advisor to many students.
03:51So what this means is that we have to add another instance of the teachers
03:55table, but not a separate advisors table.
03:58That instance will act as the parent to students.
04:01We will discuss how to handle instances in an upcoming movie, but first let's
04:05look at our entire diagram with all the relationships in place.
04:10Now although relationships are not drawn directly between the students and
04:14teachers tables, these tables are still related through a chain.
04:17For example, a student could enroll in a class that's taught by teacher;
04:23therefore that student is indirectly related to the teacher through this chain.
04:26Once our relationships are in place, we can now determine which tables need
04:31primary keys and then foreign keys.
04:33But let's start first with the primary keys.
04:36We see the following tables acting as the one, or the parent, in our diagram.
04:41Students are a parent to student classes, so they will need a primary key.
04:45And classes are also a parent to student classes, so they will also need a primary key.
04:50And teachers are a parent to classes, so teachers will also need a primary key field.
04:58Now, the advisor table is not actually its own table;
05:01it's an instance of the teacher's table.
05:04For now, since we do not need an additional advisors table, we also don't need a
05:08separate advisor primary key field.
05:10Instead, we will reuse the primary key field and the teacher table for that relationship.
05:16And now finally, the foreign keys.
05:19We apply our rule and see double hashes touching the following tables in our diagram.
05:24Classes are a child of teachers, so they need a teacher foreign key.
05:28Student classes are child to both students and classes, so we need two
05:32foreign keys there:
05:33one for students and one for classes.
05:36But let's not forget our instance of advisors.
05:40Even though it's not actually a new table, the students table is still going
05:44to be a child to advisors, so let's make sure to add a foreign key for
05:48advisors to the student table.
05:51Going through these steps for each database you create will help you verify that
05:54each relationship that you have is going to be a one to many.
05:57It will also tell you what keys you are going to need for each table.
06:01So there's a quick rundown of applying relationship design to an
06:04academic situation.
06:06Go ahead and use this example if it works for your project.
Collapse this transcript
Personnel management example
00:00In this movie, we're going to use another real-world example to apply what we've
00:04already learned about modeling relationships,
00:06but this time we're going to examine one-to-one relationships and the concept of
00:10a self-join table using an instance.
00:13Now remember, relationship modeling breaks down into three different phases.
00:18First, you develop a list of entities, or tables, that belong in the data model.
00:23And then next, you determine and diagram those relationships between the entities,
00:27and then finally, review the diagram for correctness and consistency, and revisit
00:32steps 1 and 2 if necessary.
00:35Here's another process description.
00:37And remember, when looking for entities, you want look for nouns in your description.
00:41So go ahead and pause this movie and take a minute to read this through.
00:45Using the nouns technique, we can identify the entities here as employees,
00:51benefits, and managers.
00:54Each of these appear to be different, discrete types of data, and each can be
00:58described differently from the others.
01:01Let's also make a note of the phrase "employees that are managers" for later reference.
01:07Now we have our entity candidate list, where entities will eventually become the
01:12tables that were defined in the database.
01:15Identifying the entities is only half the task;
01:18we must now evaluate how the entities are related to each other before they
01:22become tables in our database.
01:24This is where we'll create an Entity Relationship diagram, otherwise known as an ERD.
01:29In ERDs, it's common to represent your entities as a box with the entity name inside of it.
01:35So now let's move on to exploring relationships between the entities, starting
01:39first with employees and benefits.
01:41We're going to use the questions consistent with the one-to-many logic that
01:46we've been discussing throughout this title.
01:47For example, here the questions would be, can each employee have many benefits?
01:54Yes, we actually saw a reference to benefits in our process description.
01:58Now can a benefit in our system belong to more than one employee? No.
02:03If you remember, there's a phrase in our description that says "benefits
02:06each employee receives."
02:07So what we have is a one-to-many relationship.
02:10We will visually represent the relationship between employees and benefit tables
02:14with a line connecting the two boxes.
02:17The double hash is on the side of the benefits table because benefits table
02:21serves as the many, or child, in this relationship.
02:25Now in this example system, we have something interesting going on.
02:29Let's take a look at the relationship between employees and managers.
02:33If we ask a similar question here, can one employee have many managers
02:38the answer would be yes, but employees and managers are not different groups of data;
02:43they're both people with the same data being recorded in each case.
02:47And also, our process description indicates that managers are employees.
02:51So what we have here is a one-to-one relationship, meaning that a manager and
02:56employee are in fact the same entity.
03:00In this case, since they will be the same table, we'll eliminate the managers as a table.
03:05But there is a relationship between managers and employees.
03:09We saw in our description that an employee can manage other employees.
03:13What this actually means is that we need another instance of employees, not another table.
03:19This instance we will call managers will then act as the parent to employees.
03:25This is what's called a self-join relationship when one table is the parent to itself.
03:30We'll discuss how to handle instances and how to create self-joins in a later movie.
03:35But for now, we know that we don't need an additional managers table, just an instance.
03:41Let's look at our entire diagram with all the relationships in place.
03:45We can now determine which tables and keys we need.
03:48Let's start first with the primary keys.
03:51To review, we see the following table acts as a one, or a parent, in our
03:55relationship diagram.
03:57Employees are a parent to benefits,
04:00so we know we need a primary key in the employee table.
04:03However, let's not forget our instance of employees that we're calling managers.
04:07Even though it's still based on the employees table, it does act as the parent
04:11to employees in that relationship,
04:14yet it does not require its own primary key, because we're going to reuse the
04:18employee ID for the purpose of the manager's primary key in order to
04:22accommodate that relationship. Finally,
04:25the foreign keys.
04:26We see that benefits are a child of employees--
04:29note the double hash--so we'll need a foreign key inside of benefits.
04:33But let's not forget our instance of managers.
04:37Even though it's not actually a new table, employees is still going to be
04:40the child of managers,
04:42so let's make sure to add a manager foreign key to the employees table.
04:49After you go through all the data-modeling steps, you'll then know which tables,
04:53relationships, and keys you'll need.
04:55So there's a quick rundown of applying a relationship design to a
04:59human resources scenario.
05:01Go ahead and use this example if it applies to your situation.
Collapse this transcript
7. Advanced Relationship Techniques
Using global fields to filter portals
00:00In FileMaker, a portal can be thought of as a layout object that simply provides
00:04perspectives into other related tables.
00:07For example, the ones that we've got here are based in a layout that's based on
00:11the Customer table, but we're actually looking at data that is stored inside the Orders table.
00:16The portal shows rows of related data from another table, like the Orders table
00:20in this case, and as information in that distant table is added or changed, the
00:24portal will display these changes.
00:26So, all the data that you're seeing is live and dynamic.
00:28However, this is not the only way that displayed information in a portal might change.
00:33There's a technique that's called using a portal filter to change the portal's
00:37perspective, or match criteria, and thereby presenting the user with a different
00:41set of records based on information changing in the current table.
00:45That is a very powerful tool when you're developing FileMaker databases.
00:49This is the concept of creating a Portal Filter field that allows the user to
00:54change the related data that they're seeing.
00:56In this technique, you will create a field that won't act as an attribute, like
01:00all the other fields in your layout like First Name, Last Name, or Title, for
01:03example, but rather, this field will act as an input field to use as the
01:07control or the filter for the related values that they're going to see in the portal below.
01:11So let's put this technique to use in our exercise file.
01:14You see that in the file we're in the Customers layout, which is a layout
01:18based on the context of the Customer table, and we've got these three portals
01:21here all showing related orders with different criteria.
01:25But what our goal is going to be for this exercise is that we're going to
01:27combine these first two portals together, so we're going to show all the orders,
01:33but we're going to allow the user to pick which status that they want to see.
01:36So that way they don't have to just see Shipped;
01:37they could choose from Pending or New or whichever status that they like, and
01:41those will be the related order records that show up inside the portal.
01:44But first we're going to need to add a field for users to use to select their
01:48filter values, and we add fields by going into the File > Manage > Database
01:54option, and we will select Tables. And since the layout is called Customers and
02:00that's the layout where we're going to add our filter,
02:02that's where we need to define the field.
02:04So we will double-click on the Customers table, and I am going to add a new field.
02:08In this case, we want a field for the users to interact in that will not
02:12affect attribute values stored on each record.
02:14So that's why we create a new field. And FileMaker has the perfect field option
02:19for this activity, and they are called global fields.
02:21This might be something that you're already familiar with,
02:23but if not, global fields are not actually a type of a field, but rather a field
02:27that can have an option to be globally stored.
02:30By choosing a field with global storage, the field value will be shared by every
02:33record in the table, or globally.
02:35It's the same concept we used when we created these calculation fields
02:38for another exercise.
02:39But what's nice about globally stored fields is that they're going to be
02:42specific to each user's session.
02:45So, as you have a database that's shared by multiple users at the same time,
02:50the value that one user selects in their field will be different and
02:53session-specific based on the value that another user might select.
02:57So the calculations won't work in that case, but instead, we're going to create
03:00a new field which will be a text field that is just simply globally stored, and
03:05this globally stored field will allow users to pick a filter value that will
03:09affect every portal in the entire customer record, by just selecting it on one of
03:13the customer records at a time.
03:15So let's go ahead and add this new field, and I use a naming convention here
03:18too for globally stored field where I give it a prefix of a lowercase g, again,
03:23so when I see it listed elsewhere, I know that this happens to be a globally stored field.
03:28I am going to call it OrderFilter, and we will make it a type of text, and when
03:33we hit Create, you see that it's added to our Customers table.
03:37But in order to make it globally stored, we're going to have to hit the Options
03:40button and click on Storage, and all we have to do is just simply click Global
03:44Storage. And you'll see the description under Global Storage says, "A field using
03:48global storage contains only one value shared across all the records," and it can
03:52also be used as temporary storage location, temporary meaning that it's
03:55specific to just this session.
03:57So let's hit OK on this window, and we'll hit OK again, and let's go into Layout mode.
04:04So first let's make a little bit of room.
04:06What we're going to do is get rid of this portal, because it will be obsolete
04:12now that we put the new filter field on our initial portal.
04:15So let's add a field to our layout.
04:17I am going to go into Insert > Field and under the Customer Table, select the
04:24last one, gOrderFilter, and I'll put that just above the portal.
04:31And now any value that the users type into this field will act as their filter,
04:36but a really good technique is to apply a dropdown menu or a pop-up menu to a
04:41Filter field, and here this global field you'll notice is currently an edit box,
04:46but I can choose Pop-up menu. And I am going to choose a Value List that I had
04:53currently set up that points to the values inside of the order status.
04:58So you'll see here, in the Orders table it points to Shipment Status, which is
05:03the same field here.
05:04So what that does is this is going to give us a complete set of order statuses.
05:09So no matter if someone adds one on the fly, that means you don't have to go in
05:13and update your Value List.
05:14So this is really perfect for this filter.
05:16So we will hit OK and OK again, and now we have a dropdown menu assigned to that filter.
05:21If we go into Save,
05:23we see now that it is automatically showing us an indexed and alphabetized list
05:28of all of the different order statuses.
05:30But choosing a new value currently won't affect the different values that show
05:36up in a portal, because we don't have a relationship that uses that new global
05:40field as one of the match fields.
05:41That's really how this technique is working.
05:44So what we need is a new relationship that has this new global field as one of
05:48its match fields, so that the user can get the opportunity to dynamically affect
05:51the matched values, and therefore the related records that are displayed.
05:55So let's go into the File > Manage Database and then select the Relationships tab.
06:00We see that we've got all the different relationships that we've been working
06:03with thus far in the title already set up here.
06:06But we want to create a new table occurrence, or a relationship, that is going to
06:09be specific just for this filtering purpose.
06:11So to create a new table occurrence, we hit the button in the bottom left-hand
06:14corner of the screen and we will choose the table for which the data that's
06:19going to be displayed in the portal will come from.
06:22That's going to be Orders.
06:23I'm going to apply a naming convention here again. Lowercase is the context of
06:30the layout we will be using this, all caps is the context of the table that's
06:35going to be displaying the data, and then another underscore, which then I am
06:41going to put the word filtered here so I know
06:43that this is the Customer and Orders relationship that we've set up with the filter field.
06:47So I hit OK, and we see we get the table occurrence showing up on the graph.
06:55Let's make this one a different color, again so we know that it's a specialized
06:59relationship. And what we're going to do now is we're going to pick the
07:04CustomerIDpk and related to the CustomerIDfk.
07:08We seem to be starting there for all these different new types of relationships,
07:11and the reason that we're doing that is because we always want to see order
07:14records that are related to the customer record we're on, not all the different order
07:18records in the database.
07:20So now in order to add or change match fields, we'll move this over so that we
07:23can clearly see the equal sign.
07:25Double-clicking on the equal sign brings up the Edit Relationship dialog for
07:29this new relationship we've created.
07:30We'll notice that right now it's just showing us Related Orders, but we want to
07:35see related orders where the filter value is applied.
07:38So if we scroll down on the Customer side, we're going to use the new global
07:42field as one of our match fields in the relationship.
07:44But what we want to do is have the user pick one of the status values and
07:50populate the global field, and then only the related records that have the same
07:56matching value for Shipment status are going to be the ones that show up in the portal.
08:00So we've already got the CustomerIDpk = CustomerIDfk, showing us only related
08:04order records, but also only related order records where the value that the user
08:09selects in the global OrderFilter field will match the value that's in the
08:14Shipment Status for the order.
08:15So in order to do that, we're going to hit Add, and so now we see both of those
08:19values stacked in our Edit Relationship dialog.
08:23Now hit OK and OK again to close out these windows, and let's go into Layout
08:27mode, and let's make a change in this portal,
08:31so it will now use our new filtered relationship.
08:36You'll see that that updates along the bottom of the portal. And let's also
08:39change the field references real quickly for these three. Now we hit OK.
08:53Let's take a look at this in Browse mode,
08:54so we go into Browse mode.
08:57So now we've got a relationship that shows its match field just above the
09:01portal, so now let's pick one of the items from the portal.
09:04You see now what we've done is populate one of the match fields, so now it shows
09:07us all the orders that are New, and now all the related order records that are
09:12Pending or Shipped, and so on.
09:15It's important to understand that these values that the user is using inside the
09:19global field are session specific,
09:21so that way you don't have to worry about one user filtering the portal for
09:25Shipped and having another user see only shipped records in there. Each user
09:28gets their own filter selection, and that's one of the real nice things about
09:31using a global field in a case like this.
09:34Using these globally-stored filters as a portal filter can change the portal's
09:38perspective within their session, and thereby present a user with a set of
09:42related records of their choice.
09:43It's just another powerful use of portals and a great way to make the user
09:46experience in your FileMaker databases even more dynamic.
Collapse this transcript
Using global fields to create a date range filter
00:00Using a globally stored field as a portal filter for one of your relationships
00:04can allow users to change the portal's perspective within their session and
00:08thereby present users with the set of related records of their choice.
00:11Adding just one of those global fields as a filter can control the value seen in
00:15the portal, but adding two globally stored fields as a pair of filters can
00:20present users with a range of related values.
00:23So, for example, in this file that we've got here you'll see that we have got
00:26this portal for all future orders.
00:28Right now, all it does is use a relationship that's already been set up in the
00:32file, which is called customer_ORDERS_future, and it shows all order records
00:39related to the customer, but where the Sale Date value is greater than today's
00:46date--and today's data stored inside each customer record using the Get
00:50function for the current date as a calculation, so that every customer record
00:54has the same value.
00:55But let's say that we'd like to allow the user to pick a start date and an
00:59end date for the range of related order records that they see inside of a portal,
01:04and this would require that we actually set up two different filter fields.
01:08We are going to stick with globally stored fields as our filter, so users have
01:11a session-specific field that will apply filters across all of the records in
01:14the customer found set.
01:16And in order to do that, let's go into Tables and Customer tables first, and
01:21let's add one of those global filters. And since it's global, we will call it g,
01:26and we will do StartDate.
01:28What we are going to allow the users to do is pick a start date for their range for
01:31their filters and then an end date, and so we will need two different fields.
01:34And in this case these are going to be date field.
01:36So I am going to select Date and I will hit the Create button and after you hit
01:41Create, you have the Options available to you. And here I am going to choose, under
01:45the Storage tab, the Use global storage option, which works for date fields as
01:50well as text fields.
01:51And now I am going to create an gEndDate field to pair with the StartDate fields,
01:59and that's also going to be a date field.
02:01I am going to hit Create, go into my Options, go to Storage, hit Global Storage.
02:06And again, just to iterate, the global storage is session specific and
02:10it applies to all records in the found set, so they are really perfect for filtering.
02:14So while we are in here, I am going to click on the Relationships tab and we are
02:17going to add a new relationship by clicking on the Add New Table Occurrence, or
02:22Specify Table window.
02:24And this is also going to be a relationship that shows us related order records,
02:30so we will call this customers_ORDERS_range, and we will hit OK.
02:37Now this new table occurrence has been added to our graph, and we want to pick the criteria.
02:41So let's go up here, and we're going to start, just like we did with these other ones,
02:45we are going to start with the CustomerIDpk primary key going to the
02:48CustomerIDfk foreign key.
02:50That means that no matter what filter we are applying,
02:52we still want to only see the records that are related to the customer
02:55record that were on.
02:56So, that's why that's the baseline for all these different relationships.
02:59Double-clicking the equal sign will bring up the Edit Relationship dialog,
03:02where we see that we already have our match fields of CustomerIDpk and
03:06CustomerIDfk already selected.
03:09So now what we want to do is pick a StartDate filter, and we are going to match
03:14that up with the Sale Date, because that's the field, you can see it here
03:19behind our windows.
03:20The Sale Date is the date field that we are showing.
03:22So I pick Sale Date and StartDate and I hit Add. And of course, by default we
03:27see the equal sign there, but we will fix that in a second.
03:30And then I am going to pick EndDate and also pair that up with Sale Date.
03:34So right now we would really get no records that match this, but what we really
03:37want to do is show all the related customer order records where the gStartDate
03:43is actually less than the Sales Date, and so that's where we would choose one
03:47of these operators.
03:49We have to select this option first, so we can change just this operator--
03:52we don't want to change all of them. So we select gStartDate=Sale Date, and I
03:57hit the greater than sign, hit Change, and so now that's updated.
04:01And now the EndDate is actually going to be opposite, so when we select this
04:03row, we want to make sure that the value inside the EndDate field is greater
04:09than any Sale Date that shows up in our related set.
04:13So now when we are done, this is what we've got.
04:15We've actually had three different operators in three pairs of match fields.
04:18It just goes to show that when you're setting up a relationship, or one of these
04:22query relationships as I like to call them, you can have as many match fields as you want.
04:26You can get specific as you want with the operators.
04:28So it just goes to show you that you can really create relationships just for
04:32using on one layout, if need be, and it's actually quite common technique in
04:35FileMaker development.
04:37Once your relationship is in place, we will hit OK, and let's give this one
04:42a little different color as well, just so we can identify it from some of the other ones.
04:48We will hit OK, and let's go into Layout mode now.
04:52In here we show the all future orders.
04:55What we really want to do is show a date range, so we are going to start with one field.
04:59Let's use our Field Insertion tool to drag the StartDate onto our layout. And we
05:10will drag another one, which will be the EndDate. And really we can get rid of
05:19these if we want. We can just choose range.
05:25Okay, so these are both global, and since they are going to be dates, why don't
05:29we add something by selecting the field?
05:33We will add a control style of dropdown calendar, including the icon, so that
05:38users know that they're picking from dates, make it a little bit easier for them.
05:42Drop-down calendar > Include icon, make that a little larger. All right!
05:48So now we have got a date field that's got global storage for StartDate and
05:51EndDate, and we have set up a relationship to show us a range of related order
05:55records in between those two dates.
05:57And so now we want to make sure that our related fields inside the portal and
06:01the portal itself are pointing to the relationship that we set up.
06:05See, right now they're still pointing to the
06:06customers_ORDERS_future relationship.
06:08We'll double-click on this and drag down to range.
06:13Hit OK and we will do the same thing, and notice that the correct field stays
06:18selected if we change the relationship.
06:21ORDERS_future, set range and one more.
06:26So what we have done here is made all three fields in the portal based on the
06:31new relationship that we just set up, and the new relationship uses these two
06:35global fields as match fields.
06:37So now in Browse mode, after we Save our values, we see that we don't have any
06:41values, because we haven't set up our match field range yet.
06:44So let's test this out.
06:46I'll go in and add a date for StartDate, and let's say the EndDate of
06:58couple months later.
06:59And now we see that the records are only showing me values that fall within
07:04this date range, so between July 2nd and September 21st, and if I want to change that, I could.
07:13Those all stay the same.
07:14I could say July 2nd and July 11th.
07:18You can pick whatever range you want.
07:20So this will maintain the same global filter values for every customer record, as
07:25you see I moved through all these different records, and it will be session
07:29specific, so my selections in the date range the high and low end of the scale
07:33won't affect anyone else's.
07:35I use dates, but you can use the same technique with numbers to determine a
07:38range, or even time fields to determine a range.
07:41Using these pairs of globally stored fields as portal filters in combination
07:45with multiple match fields and different operators inside our Edit Relationship
07:49dialog can change the portal's perspective within a user session and thereby
07:53present the user with a set of related records of their choice.
07:56It's just another powerful use of portals and a great way to make the user
07:59experience in your FileMaker database even more dynamic.
Collapse this transcript
Using relationships in a script to navigate
00:00Once you've established some table relationships inside your FileMaker file,
00:03you can start benefiting from some of the relationship-based functionality inside FileMaker.
00:08We've already discussed in previous movies in this chapter the ability to use
00:11related fields in your layouts, which are basically borrowing a field value
00:14from a parent table.
00:15And you see here in this layout we've already discussed how we can add portals,
00:20a layout object that allows you to see related child records from the context
00:23of your parent record.
00:25And now I'm going to show you how relationships can benefit you outside of just
00:28using layout objects, but instead, inside of your scripts.
00:31So first a couple of quick items. If you're not already familiar, a script is
00:34something in FileMaker that allows you to save stored actions in a sequence and
00:38allow them to be triggered by some user action.
00:41Scripts can be set up under the Manage Scripts dialog.
00:46You create a script and choose from the series of different script steps.
00:49What we're going to do here is create a script and attach it to this button here
00:56on our Order layout,
00:57this button for the printer icon. This will allow users to select the print
01:02icon, which will then allow them to go to a print-ready layout that shows all of
01:07their related OrderLineItem records formatted in a way they can print that doesn't have a portal.
01:13And the trick there is that a layout for print purposes that doesn't have a
01:18portal on it that shows OrderLineItem records will have to be based on the
01:22OrderLineItem table, thus a different context.
01:25And we already have the order print layout built, if you look in Layout mode and
01:30go to Print Layouts > Order_Print, and we'll see that the context of this layout
01:35by selecting the Layout Setup icon, is the OrderLineItem.
01:44So we're not just navigating to a different layout, but we're navigating to an
01:48entirely different context. And just to review this idea of context, let's go
01:52under Manage > Database and look at our Relationships tab.
01:55So here's the table that this layout is based on, and here's the table that the
02:00print layout is based on.
02:02You see that we have a relationship between these two, and it happens to be one
02:05order has many related OrderLineItem records.
02:09That's why this one order record has many related portal rows, and this portal is
02:16directed towards the OrderLineItem relationship.
02:20So given all of that information, what we want to do is create a script that has
02:24the following tasks assigned to it.
02:27We need to navigate over to the OrderLineItem table context and go to the
02:31layout that we've set up for printing an order, and then we want to isolate a
02:35found set of only those OrderLineItem records that are child records to the
02:39order that we're on--
02:40so basically, all the ones that we've seen in this portal and only the ones we've
02:43seen in this portal.
02:45And then finally we'd like to present this new layout and new found set in a new window.
02:49So really if you're a little bit familiar with scripts, you know that scripts
02:52have different steps, and what I just rambled off is about three may be four
02:56different script steps, which would normally require that we go and generate a script for this.
03:01But instead I'm going to go into Layout mode and I'm going to show you one
03:04simple script step that we can assign to this button that would allow us to do
03:08all of those things in one shot.
03:10So let's select the button and go under Format to Button Setup, and here we can
03:16just assign a single script step to a button or layout object. And we only have
03:21one that we need, so we're going to go to Go to Related Record, and now I'll hit
03:24the Specify button, and we've got a couple of decisions to make here.
03:28First, we want to see related records from.
03:31It's important to understand what that means.
03:32So when we navigate over to a different context, what is that different
03:37context going to be? So in this case we're going to be in the Orders table
03:41and we want to see related records from OrderLineItem. So parent Order, Child OrderLineItems.
03:49Now we get to choose which layout we see, and we're going to see a list of
03:52layouts listed here that are all based on the OrderLineItem table, and
03:56there's only two of them, and we're going to pick the one that we set up to
03:59print out our order details.
04:01And the reason that we've got it based on OrderLineItem is so that we can have
04:04one row for each OrderLineItem, and then we borrow related values from the order
04:10record, or the parent order record, to display in the header and footer of that
04:14layout, a pretty common technique for printing related records.
04:18We'll hit OK, and now we will also say, yes, we'd like to show this in a new window,
04:23and we'll call this Order Items. And the window will be let's say 700 pixels
04:32high, 500 wide, so it's smaller than the one behind it, so we can see that
04:37it's a pop-up window.
04:38And this is a really important option here, Show only related records; otherwise
04:41it will just navigate us to the OrderLineItem context and not show just the
04:46records in the found set.
04:47This is creating records in a found set that are only going to be related to
04:51this order that we're on.
04:52So we hit OK there, and we hit OK again.
04:56So in summary, this one script step will open up a new window, navigate to the
05:00order print layout, which is based on OrderLineItem, and then show us related
05:04records inside of the OrderLineItem table, but only the related records related
05:08to the order record that we're currently on.
05:11It happens to be just showing us the same data that we're seeing in the portal, and
05:14this works inside of the script step because we already have a relationship
05:17between the Order Table and OrderLineItems that's set up in our database; if not,
05:21we could have just created one.
05:23Let's go into Browse mode and take a look at this one in action, and let's see what happens.
05:28So here I am. On the first order I see I have a series of related order
05:32records, and I'll hit OK.
05:35And so now it opens up the new window, and we see that it contains the same
05:40records - Snow Tire, Accessory, Bike Helmet, Snow Tire, Accessory, Bike
05:44Helmet, gel-settle, and it isolates all of those for us, puts them in a nice
05:48layout so that we can print these, and you'll notice that if I go to a
05:51different record--let's say this one--
05:57it shows all those related records instead, so it's dynamic.
06:00And what's nice about it is that you can have as many of these as you'd like.
06:03No matter how many related records that you've got, it'll expand--since we're in
06:08a List view here, we'll look at Layout mode.
06:11This is actually the context of OrderLineItem and everything in the header are
06:18related fields that are coming from customer.
06:21So we're borrowing from the parent--
06:23we're actually borrowing from our grandparent in this case because we're saying
06:27we're in OrderLineItems and we're going up to the order and finding the customer
06:31related to that order, so you see that you can not only borrow from the parent
06:34tables but also the grandparent tables.
06:36Then we simply set up a body that shows OrderLineItem fields peppered in with
06:42some product fields.
06:44Here's our OrderLineItem fields right there, and then we put in a related record
06:48that we're borrowing from the parent.
06:49We borrow from the parent here, grandparent here, parent here as well.
06:53You can take a closer look at the Order Print layout if you have access to
06:57the exercise files.
06:59So again there is a bunch of interesting things that you can do with navigating
07:02users to other layouts once you've established relationships between tables;
07:06allowing your users to print the contents of a portal without having to
07:09print the portal itself is simply one of them.
Collapse this transcript
Using portals to connect to data more than one table away
00:00Thus far in our examples, we've worked with showing child records in a portal in
00:03the context of a parent.
00:05For example, if you look on screen, we are looking at a layout that's based on
00:09the Customer table, and what we have got here in the bottom are two portals that
00:13are showing related Order records.
00:15So the Customer table is the parent table in this relationship, and the Order
00:19table is the child table.
00:20A lot of people like to call this "looking at related records from one table away."
00:24But when we were discussing the concept of diagramming your relationships, I
00:28mentioned how parent tables are not only related to the child tables but are
00:33also related to all linked tables through a chain of relationships.
00:37And if we go under the File > Manage > Database, in the Relationships tab I can
00:40show you visually how this works.
00:42So we already know that the Customers table and the Orders table are related to each other.
00:47So of course, I can view all my related order records in a portal.
00:50But let's say in the context of a Customer table I decide that I am going to put
00:55a portal based on the OrderLineItem record instead.
00:58Well, what I'm actually going to see in that case, are all OrderLineItem records
01:03that appeared on an order that was related to this customer.
01:06So we can see related data that is more than one table away, and you can go as
01:11far down your chain of relationships as you have relationships in your database.
01:15So, for example, I could go all the way to the end, where Products and Customers
01:20are actually related to each other through this chain, and I could say, instead
01:24of showing me all products in a portal, show me all products that appeared on an
01:29OrderLineItem on an order related to a customer--
01:33so essentially, all the different products that they have ordered. And what
01:35else is nice about this is that it will give me a list of products without any duplicates in it.
01:40As complicated as this concept might be, the overhead is almost minimal because
01:44we're going to use existing relationships, and it's really easy to create a
01:49portal in your layout.
01:50You go into Layout mode and you click on your Portal Drawing tool, so
01:57really not having to create any relationships, and simply choosing Products in
02:02this example, hit OK, and let's simply just hit Product Name, and we will move that over.
02:10And just to reiterate the point here, we are looking at a table that is actually
02:14four tables away, but it's still related to the Customer table.
02:19And when we go into Browse mode, we would be able to see that little bit more dramatically.
02:22So now we are on customer number one, and here are all the different products
02:26that this customer has ordered. And there are new duplicates, even they have
02:29ordered 50 Bike Helmets and 20 SpeedGel Saddles.
02:32It tells us that they've ordered at least one of these things.
02:35So that the fact that there's actually values showing up in the Products
02:38portal means that a product has appeared as an OrderLineItem on an order
02:43related to this customer.
02:44If the customer has no orders, nothing will show up.
02:46If the customer has Orders but don't have any OrderLineItems, nothing will show up there.
02:51So the entire chain has to have related records all the way through it in order
02:54for this data to appear, but that will be logical based on the data that's
02:58entered into the system as well.
02:59So going back to our original customer record, this basically means that we can
03:03view related data in our portals and related fields can give us an entirely
03:07different way to visualize the related data in our database, but with absolutely
03:11no programming overhead.
03:13These are the types of value-added possibilities that are built right inside
03:16your database just because you decided to use related tables.
03:19And this can be rather useful, for example, if you wanted to go into Find mode
03:26and do a search in this related portal.
03:28So let's say I want to search for a product and I hit Perform Find.
03:34So what this has actually done is created a found set of records, so it's
03:37telling me that 21 out of 22 customers have ordered the Bonsai toolset before.
03:42So if I want to do an incentive program, or we are doing a sale on these things,
03:46I can use that portal that's more than one table away to help me do searches or
03:50just display data inside of the context of our customer layout
03:54that can help me find out who has ordered what and see if any of these products,
03:57let's say aren't that popular or some of them are very popular, I can find out
04:01which customers are buying them.
04:03So setting up a proper relationship structure in your files can help you view
04:06related child records, but it also gives you visibility into any related table
04:11inside your database, all of this without having to make any special
04:14relationships and almost no overhead.
Collapse this transcript
Creating self-relationships
00:00We've been looking at various ways to visualize and work with data from other
00:03related tables in a properly architected relational FileMaker database,
00:07and in this movie, we're going to discuss how you can actually view related
00:11data, but from the same table that you are currently in.
00:13So unlike other relationships where we focused on putting a portal, or a related field,
00:18on a layout and having to pay special attention to the context of the layout as
00:22well as the context of the data in the portal-related field, here we're going to
00:26put a related field and a portal on a layout where a layout and the related field
00:31have the same context.
00:33Let's first create a story behind this exercise.
00:35In this case, let's say we're going to put a field on each customer record right
00:39over here where it says Referred By, and in that field we're going to store the
00:43ID of the customer who referred the customer record that we're on.
00:46So if such and such organization refers another customer over to our company
00:52then we're going to put the ID of the referring account into that field.
00:56So something like this can allow you to do referral programs and pay out
00:59commissions and do different functions without having to add any new tables.
01:03So first we're going to need a field where we would store that ID, and this
01:07field will actually act as a foreign key in this new relationship we're going to create.
01:12So let's go into the File > Manage > Database > Tables tab and inside Customers
01:21what we're going to do is create a foreign key for relationships from customer
01:26ID back to the customer table itself.
01:29In this case, we're going to call it the Referral ID and as with any other
01:33foreign keys, we will do these single underscore.
01:39So we've created a field, and it's going to be a text field. We simply hit the
01:42Create button, and now we've added a foreign key field to the customer table.
01:47Ignore for a moment that this is the same table that's going to contain the
01:50primary key field in this relationship.
01:52We'll get to that in a second.
01:54So now we'll hit OK, and in Layout mode let's add a field, and we'll
02:06choose _ReferralID.
02:08Line it up a little.
02:10So now what we're going to do is allow users to populate this field with the ID
02:15of the customer record who referred them.
02:17To make it a little bit easier, let's go over to our Inspector and instead of
02:21having an Edit box, let's call this a Pop-up menu, and we'll choose a value list that's
02:26already been set up in our system that shows all of the primary key values from
02:33the Customer table, along with the Company name, so that users know which primary
02:38keys go with which customers.
02:41So, simply adding that pop-up menu control style to the existing referral field
02:47will then allow us to go through, record by record, and assign referral values.
02:54So let's say we pick a few different records in here, and they're all referred to
03:02us by the BooJax Corporation, just so we have some related data to work with.
03:08And you could pick a series of different ones if you'd like to.
03:12So now we have a field that allows us to store who referred whom.
03:16And in this story we're also going with the assumption that only one other
03:20customer can refer a customer,
03:22so that's why we're using a field where only one value can be stored.
03:25This makes the customers the parent and in this concept of referrals that
03:30becomes our child, even though they are still going to be based on the same table.
03:34This means that the customers must have both a primary key to uniquely identify
03:39each record, but must also have a foreign key added that will be populated only
03:43when they've been referred.
03:45Let's go into the Manage Database window and take a look at this a little bit more visually.
03:51Go into the Relationships tab, and what we want to do is create a new
03:54relationship and like any other of these query type of relationships that we create,
03:59we're going to go down to the bottom left-hand corner and create a new table
04:03occurrence, but this time if you think about what we want to see inside of a
04:06portal, for example, it's going to be Customer records,
04:09so we're going to base this relationship on the Customer table. And we'll still
04:14use our same naming convention, customers_REFERRALS, and we'll place that over
04:25here, give it a little bit different color.
04:30And now what we're going to do is, if we think this through is in a portal
04:34that we would place on the customer table, it's what data do we want to see in the portal?
04:38It's always a good way to think about what your match fields are going to be.
04:41So we'll say that we want to see all of the customer records that were
04:44records that are the referrals for the active customer record that we're on at the moment.
04:50So in order to do that, what we're going to do is use the Customer ID as the
04:55primary key, but instead we're going to use a different field.
05:00Sometimes it's tricky to scroll through all these.
05:02I'll show you a little trick.
05:04If you just pick any field and then double-click on the equal sign, now you can
05:08use a little bit easier interface to pick the one that you'd like.
05:10So we'll go CustomerIDpk in the customer table to the _ReferralIDfk also in
05:17the customer table.
05:18It doesn't matter that they're in the same table; we're still able to create a
05:20relationship between these two.
05:21I'm going to hit Change, and this is all we need.
05:24We need the CustomerID=ReferralID, and now when we hit OK, close that window out,
05:31and we see we've got a tab here for Referrals.
05:34I'm going to go into Layout mode, click in the Referrals tab, and I'm going to add a Portal.
05:40What I want to see here, all the different customers that I've referred if I'm this customer.
05:45So I'm going to choose the new relationship we just set up called
05:49customers_REFERRALS,
05:50do a little vertical scrollbar, hit OK, and I'm just going to pick the Company
05:56name, and now we hit OK.
05:58Let's see what we get when we go into Browse mode.
06:02So now if I go find the record that we used for all the referrals and click
06:10over into the Referrals tab, now you see that it gives me a list of 1, 2, 3, 4,
06:145 different records.
06:16And so now we can do some searches inside our database if we want to.
06:20Go in here and use the Search Operator, like the Asterisk tool, to tell me if I
06:24have any values in any fields.
06:27Do a search there and it shows me that only one record out of all of these 22
06:31has even done any referrals, and it shows me which referrals those are.
06:34Now then also by having this foreign key value on each record we can then
06:40navigate one at a time to see who referred each customer that's inside of our database.
06:45So relationships can give us the opportunity to view data in other tables
06:49through the base relationships, but they can also give us some compelling ways
06:52to link and view records that are stored within the same table.
Collapse this transcript
8. Relationships in Calculation
Creating aggregate functions using relationships
00:00So far in this title we've looked at how to create relationships to establish
00:03the architecture of our database and then how to use those relationships, or
00:07even create specialized ones, to use with layout objects like related fields and
00:11portals in our layouts. We've also looked at incorporating these relationships into our scripts.
00:16In FileMaker our architecture combined with our scripts are a large part of the
00:20schema of our database,
00:21but one important area of the schema that we have not yet looked at are calculations.
00:26Calculation fields and calculation dialogs are found throughout the FileMaker
00:30interface, and they are there to add another dimension to your FileMaker solution--
00:34and related fields can be used within those calculation dialogs.
00:37This can be a very powerful way to leverage relationships to aggregate related
00:41data throughout your database.
00:43Let me show you a couple of examples.
00:44These are easy to do and they can give you a lot of value back with very little overhead.
00:49In the first example what I am going to do is create a calculation for subtotal
00:53that dynamically totals up all of the different related extended price values.
00:58So no matter how many different related records there are, it will go and
01:01add all those up, and then that can be displayed as calculation result
01:05inside the Subtotal field.
01:07So let's go into File > Manage > Database, and let's find the Subtotal field.
01:15You see we've got Subtotal. It's set up as a calculation, but it doesn't have
01:18a formula in it yet.
01:19So let's just go ahead and hit Options, and we'll get rid of the two quotes and
01:23this field is intended to give us the total of the extended price.
01:27Now, assuming that you're familiar with calculations already, you know that
01:30calculations are fields that you don't enter data into, but instead provide a
01:34formula to FileMaker, so that FileMaker can go gather the appropriate
01:38information and then display the result based on your instruction.
01:42Any field that you place in a calculation formula acts as a placeholder, meaning
01:47that FileMaker will process these instructions in the formula for every record
01:51in your table but will use the data in the fields referenced as it processes.
01:55So for example, if I were to just put the Order ID into my calculation, it's
02:00not going to actually result in the word Order ID;
02:03it's going to result in whatever the value is that's stored inside the Order ID
02:06field. And a calculation gets processed for every record in your table, so really
02:11these fields are just placeholders for the data that's stored within a field.
02:14Just like you can use related fields inside of a layout, you can also use them
02:18in a calculation dialog.
02:20But just like a layout, the context of the calculation will depend on what
02:24values you get inside of those fields.
02:25So you may not have noticed, but up on the very top of this field we've got a
02:29dropdown menu that lets us choose different contexts to use for a relationship.
02:33So the idea of context when we're looking at a layout and determining what
02:37related portal we want to put on it, for example, tells us from what context
02:41we're looking and what data we're going to see.
02:44So this is where we choose from what context we're looking at, and you see here,
02:48here's all the relationships that are based on the Order table, and we're going
02:51to stick with the Orders one as the default.
02:54So that tells us that we're defining this field inside of Orders.
02:59That's going to be our context and any related field we put in here--
03:02if we look at our Manage Relationships, we can see this visually--
03:07if we base it on orders, that means that if we put any related fields from order
03:11line items, those are going to be the child, and if we put any fields from the
03:16products table, those will be the grandchild in this case.
03:19So we'll have many related records if we use related values from either of these
03:23tables. But if we put the customer field inside of a calculation that has an
03:28Orders context, it's only going to have one related value. So anytime we go
03:32upstream, so to speak, there will only be one related value; and anytime we go
03:36downstream in the relationship, there will be multiple related values.
03:39So back in this context what we want to do here is we want to simply summarize
03:43all of the extended price fields from one of the child tables.
03:47So as you see, we can click on the current table where it says Orders and we can
03:53choose a different related table and fields from that related table.
03:57So here you see OrderLineItem, and we've got the Extended Price field.
04:00But what I'd like to do is total up all those values,
04:03so I am going to go under the function listing here on the right-hand side and I
04:07am going to choose Aggregate functions and I am going to double-click on Sum.
04:12So in the case of the Sum function it gives some parameters inside the
04:15parentheses here that are supposed to act as sort of helpers so that you know
04:18what kind of fields to put here.
04:20And what this one is asking us to do is pick a semicolon-delimited list of
04:25different fields so that it can summarize all the values within those fields.
04:29Now, you could put in a bunch of different fields that are in the Order table
04:32and it would just go and add all those up,
04:34but nine times out of ten you'll be using these aggregate functions to
04:38aggregate related data.
04:40So by simply putting a related field, let's say Extended Price, into the Sum
04:44function as the single parameter, instead of this field just being a
04:48placeholder for one field value, it's actually a placeholder for every related
04:53record that you may have.
04:54So if this order has ten different order line items on it, this is actually
04:58going to summarize an array of ten extended price values, and that's going to
05:02change for every record.
05:04So this really is a placeholder for an array of related values. And this is
05:08a very popular trick that FileMaker developers use, simply putting one
05:12single related field in there in between the parentheses instead of having
05:15several individual ones.
05:17Now keep in mind that this technique will only work when you're defining a
05:20calculation in the parent table.
05:22If you try this on the child table with a related parent record, you'll only
05:25ever have one related record anyway, so the sum doesn't even make any sense.
05:29Now if you remember, Order is the parent in this relationship with
05:32OrderLineItem, so this will make sense.
05:35This is all you need to do inside your Calculation window, and you've got to make
05:38sure that your calculation result is a number. And we'll hit OK and hit OK again,
05:44and now you see our value is adding up all of the different related
05:48OrderLineItem records and presenting that value to us inside the Subtotal field,
05:53and that changes from record to record within our customer database.
05:58Let's just do one more really quick example in another table, just to make
06:02sure this makes sense.
06:03Let's go under the Customer table, and remember, we have all the
06:06different referrals here.
06:08Now personally, when I am developing databases I like to create aggregate
06:11calculations with related field references for nearly every portal that I
06:14display on a layout.
06:15I happen to find that they make sense in a lot of cases.
06:17It's not a rule by any means, but I just think it's a good practice.
06:21It's another one of those areas where since you already have the
06:24relationships in place,
06:25why not use them to provide you data that you won't normally have if you were
06:28just simply using a flat file?
06:30So let's say, for example, that we wanted to know the total number of referrals
06:33for each customer record.
06:34This could, let's say, help us with an incentive program that we're running.
06:37So if we go into the File > Manage > Database, we see in the Relationships we
06:43already have a customer referral relationship set up.
06:47It's a self-join table with the relationships between customers and customers,
06:53which is currently displaying all the referrals for any given customer.
06:58So these are all the different customer records that were referred to the
07:02company using the database by the BooJax Corporation.
07:06But let's say we have an incentive program that says that anybody who has
07:09more than three referrals gets a certain discount on their next order,
07:12something along those lines.
07:14Then we would certainly want to have a field inside the customer table that told
07:18us the total number of referrals.
07:20So let's create one of those.
07:21We go File > Manage > Database, go into Fields, and we're going to find that
07:26field inside Customers, and we're going to call it TotalReferrals.
07:33Let's make that a calculation, hit Create, and we're going to keep it the context
07:40of Customers, and let's go down to the Aggregate functions. And instead of Sum,
07:44let's just use Count, and this function is similar to the Sum function, but
07:47instead of totaling up the numeric value in each related field within your
07:51array, it's actually going to count all non-empty related fields and give us the
07:56total number of those non-empty related fields.
07:58So let's first put a related field inside of this as a parameter.
08:02Let's choose customer_REFERRALS.
08:05Now what we want to do when we're using the Count function is we want to pick a
08:08field to draw our array where that field is always going to be populated if
08:14it's a related record.
08:15So what field do we know will always have a value in it in all related records
08:20for customer_REFERRALS?
08:21Well, we know that's the foreign key field.
08:23So another thing I like to do when I am developing databases is always choose
08:27the foreign key fields, the related foreign key fields I should say, inside of my
08:32Count functions for aggregating related records.
08:35So in this case it should look like Count (customers_REFERRALS::_ReferralIDfk).
08:40We see that the table name indicates that this is a related value, and so now we
08:45have this as a number.
08:47I hit OK, I say OK again, and you go into Layout mode and simply drag a field
08:55below your portal, scroll down to TotalReferrals, and now with very little
09:02programming you've got an aggregate function that will go through each record in
09:08your database and give you a total count of all the different related referral
09:13records. And this is something that you can search inside of,
09:16so let's say I want to do everybody greater than 3 referrals qualifies for our
09:22referral discount, and I hit Perform Find and I find out that I have one record
09:27in my database that matches that.
09:28Using related fields in your calculations, especially if you aggregate these
09:32calculations in the context of a parent, can provide some very useful and dynamic
09:37values, again, with very little overhead.
09:39These fields can then be placed in your layouts as summaries or related values in portals.
09:44They can even be used in fine criteria just like any other field.
Collapse this transcript
Using the List function
00:00The List functions is one of my favorite functions in FileMaker.
00:03It's a simple function that does just what its name indicates,
00:05it produces a list.
00:07But when you combine that with other functions in FileMaker calculation dialogs,
00:10it can become very powerful.
00:12Let we show you a list function and take a look at the value it produces, so we
00:16can kind of start there with your understanding of how this can help enhance
00:20your FileMaker database.
00:22We will go under the Manage Database dialog, under Fields, and under Customers,
00:27we are to create a New Field called OrderList.
00:30Let's make this one a calculation so that we can use Calculation function, and hit Create.
00:36The list function is an aggregate function found in the Aggregate function
00:40group, and much like the other aggregate functions, the parameters that it has
00:45are just a series of different fields inside the parentheses. And since all it's
00:49doing is creating a return-delimited list of values, it doesn't really make much
00:54sense to just put a bunch of local fields in here, since really you could just
00:59create a calculation that lists all these different fields concatenated
01:03together with return characters.
01:05So the true power of the list function comes when you put a related value in
01:10between the parentheses, in order for it to process, and of course only a
01:14related value that comes from the child table in a parent-child relationship.
01:19So the child table to the customer table is the Orders table. And let's go down
01:26here and pick Sale Date.
01:29So now what we've instructed it to do is find all of the related order records
01:34and extract only the sale date from them, and display those in a returned-
01:38delimited array of related information.
01:41Now you think that we would put dates because of the date field, but instead I
01:44am going to suggest that you choose Text, because I want to show you another
01:48function that needs it to be text later in this exercise. So we'll hit OK, hit OK
01:53again, and now let's go to Layout mode and just add this list function to our
01:58layout so we can see what it does, before we move forward with our exercise.
02:03So here's the Order list. And since it's going to be a returned-delimited list,
02:11we will make it little bit larger, and we will get rid of that bold and the
02:15underline, and we'll save our changes.
02:20And in Browse mode now we see, looking at a List Function right next to a
02:25portal with the same related value,
02:26you see that they are listed in the same order and have the same number of values.
02:31So really it's almost like a text version of a portal showing one of the values
02:36from within that portal.
02:37It is like extracting a column, and these values change as we go from customer
02:40record to customer record.
02:42Nothing too dramatic here, but this could be helpful to you in its existing
02:46form. For example, if you want to print all of the related values in the context
02:49of a parent, without having to print a portal you can combine that with Sliding
02:54and Printing Layout options, and this could allow you to print related values
02:56without the hassle of a portal.
02:58But the real values are when we combine this list, or this array of related
03:02values, with other functions inside of FileMaker.
03:05So before we proceed with this exercise, I want to have you pay special attention
03:09to the order in which these dates are listed.
03:13You see that they are the same order that the portal uses, and the portal
03:17doesn't have a Sort Order specified in it, as we can see by going under Manage >
03:23Database > Relationships,. If we double-click on the equal sign between the two
03:27related tables, that brings us to our Edit Relationship dialog, and we see that
03:32we don't have the Sort Records option selected, so then what FileMaker does is
03:38it chooses by default the order in which the records were created. So both in
03:42the portal that we're looking at and in the list array that we've created with
03:46the related values, they are listed in the order they were created.
03:50But let's mix this up a little bit.
03:51Let's say that we want to sort the related records by the sale dates in
03:55descending order. We will choose Descending, and now this is going to show
04:02us the most current date on top, and on the very bottom of the list, show you the latest date.
04:07So what this means is that the most current order will show up at the top of our
04:10portal and on our list view, and the reason for that is the relationship that
04:14both of those objects are based on has this Sort value in it.
04:19So anything that references this relationship will now have a new sort value,
04:22but we see that the most recent versions are on top, and this is good
04:25because what if we could just skim off the top of our list the very top date?
04:30That would mean that we could have a field that would tell us what the last order date is.
04:34So let's go into our Manage Database again, into our Tables and Customer
04:40tables, and let's create a Field that's called LastOrderDate.
04:46And we will make that Calculation.
04:48Now I am going to show you a different Calculation function that extracts values
04:54from an array of different values, and this one is called the GetValues
04:59function. And if you scroll down into your normal list, you'll see that you've
05:03got several different functions that starts off with Get, but we'll take
05:06GetValue, and it has two parameters.
05:09It says give me a listOfValues and then tell me which Value you want out of that list.
05:14And what's interesting about having our OrderList field already defined is that
05:20this is in fact a list of Values.
05:23So we put the Order List in there and it acts as a placeholder for our list,
05:27then we can say which value out of those we want.
05:29And if we say number one, it takes the top; if we say number two it takes second
05:33one down; and so on; and so on.
05:35So I am going to say number 1, I am going to make this a Date, and if we hit OK,
05:40and Ok again, go into Layout mode, and instead of having all of the orders on
05:46there, let's just say that we pick our new field, add it to our Layout, and now
05:56let's look at this in Browse mode. And what it does is it goes through and
06:02creates a list based on the Sort Order set up in the Relationship, and it skims
06:06the top Date value off of the top of that list.
06:09And since we purposely made the Sort value have the most recent order on top,
06:14we know that we can faithfully extract the value off of the top of our Order
06:17List field, and that gives us the last order date.
06:21And in addition, this field will automatically update every time a new order is
06:24created and will display the most recent order at any given time.
06:28We can search in this field by simply entering a year, for example, let's say
06:34last year, and what that can do is give me a found set.
06:39Let's see, I have got 1 record in my Customer table, and basically this tells me
06:43that this is a customer that hasn't ordered anything from us in the last year.
06:47So the list function provides a great way to isolate a list of related values in
06:51the form of an array, and that array, or list, can be used for printing in the
06:55parent context, but when it's combined with other functions inside FileMaker, it
06:59can give you some really useful ways to display and work with related data.
Collapse this transcript
Conclusion
Next steps
00:00I hope you enjoyed Relational Database Design with FileMaker Pro.
00:03Understanding relationships in FileMaker is really the key to taking your
00:06programming skills to the next level.
00:08There is a lot of important concepts in this title, so if you are not sure about
00:11anything that I've covered in this course then feel free to come back and check
00:15out these chapters for a refresher.
00:17If you're looking to brush up on your FileMaker skills, I'd encourage you
00:20to check out the FileMaker Pro Essential Training title on the lynda.com
00:23Online Training Library.
00:24So, good luck architecting your databases, and we'll see you next time.
Collapse this transcript


Suggested courses to watch next:

FileMaker Pro 12 Essential Training (10h 28m)
Cris Ippolite

FileMaker Pro 11 Essential Training (9h 11m)
Cris Ippolite


Foundations of Programming: Databases (3h 11m)
Simon Allardice

Project Management Fundamentals (2h 7m)
Bonnie Biafore


Are you sure you want to delete this bookmark?

cancel

Bookmark this Tutorial

Name

Description

{0} characters left

Tags

Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading
cancel

bookmark this course

{0} characters left Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading

Error:

go to playlists »

Create new playlist

name:
description:
save cancel

You must be a lynda.com member to watch this video.

Every course in the lynda.com library contains free videos that let you assess the quality of our tutorials before you subscribe—just click on the blue links to watch them. Become a member to access all 104,141 instructional videos.

get started learn more

If you are already an active lynda.com member, please log in to access the lynda.com library.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Access to lynda.com videos

Your organization has a limited access membership to the lynda.com library that allows access to only a specific, limited selection of courses.

You don't have access to this video.

You're logged in as an account administrator, but your membership is not active.

Contact a Training Solutions Advisor at 1 (888) 335-9632.

How to access this video.

If this course is one of your five classes, then your class currently isn't in session.

If you want to watch this video and it is not part of your class, upgrade your membership for unlimited access to the full library of 2,025 courses anytime, anywhere.

learn more upgrade

You can always watch the free content included in every course.

Questions? Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com.

You don't have access to this video.

You're logged in as an account administrator, but your membership is no longer active. You can still access reports and account information.

To reactivate your account, contact a Training Solutions Advisor at 1 1 (888) 335-9632.

Need help accessing this video?

You can't access this video from your master administrator account.

Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com for help accessing this video.

preview image of new course page

Try our new course pages

Explore our redesigned course pages, and tell us about your experience.

If you want to switch back to the old view, change your site preferences from the my account menu.

Try the new pages No, thanks

site feedback

Thanks for signing up.

We’ll send you a confirmation email shortly.


By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked