ColdFusion 9 New Features
Illustration by Don Barnett

Defining table relationships


From:

ColdFusion 9 New Features

with Daniel Short

Video: Defining table relationships

So far we've been dealing with a single object at a time. But in the application world you never have objects that act in isolation. The key to any good application is how it handles related bits of information, using links between tables. In this video we are going to cover how to define foreign key relationships between your objects and how those objects get returned to you when pulling the entities out of the database. So in Chapter5 open up tablerelationships.cfm. Like before, all we are doing is loading a single entity and dumping it out to the screen.
Expand all | Collapse all
  1. 4m 30s
    1. Welcome
      53s
    2. Using the exercise files
      3m 37s
  2. 7m 49s
    1. Adding managing and comparing servers
      5m 26s
    2. Monitoring server health
      2m 23s
  3. 22m 10s
    1. Setting the default data source and SMTP
      5m 6s
    2. Getting programmatic debugging and exception handling
      5m 54s
    3. Reviewing the new onCFCRequest method
      5m 29s
    4. Using ApplicationStop()
      2m 24s
    5. Working with Server.cfc and onServerStart
      3m 17s
  4. 17m 45s
    1. Using ternary and chained operations
      5m 46s
    2. Using New and Import
      4m 2s
    3. Reviewing CFScript enhancements
      7m 57s
  5. 20m 23s
    1. Building with implicit getters and setters
      4m 26s
    2. Working with LOCAL scope in functions
      4m 35s
    3. Serializing objects
      6m 6s
    4. Writing components in CFScript
      5m 16s
  6. 19m 27s
    1. Getting started with ORM
      5m 51s
    2. Logging ORM activity
      2m 13s
    3. Saving objects to the database
      6m 10s
    4. Defining table relationships
      5m 13s
  7. 16m 59s
    1. Caching page fragments
      5m 29s
    2. Managing the cache
      4m 48s
    3. Working with in-memory files using VFS (RAM disks)
      6m 42s
  8. 12m 39s
    1. Working with Excel spreadsheets
      4m 56s
    2. Working with Word documents
      4m 4s
    3. Working with PowerPoint presentations
      3m 39s
  9. 28m 59s
    1. Loading Google maps with markers onto a page
      4m 53s
    2. Adding a Flash movie with the built-in FLV player
      2m 14s
    3. Using multi-file upload control
      6m 7s
    4. Building a progress indicator
      3m 37s
    5. Working with accordion layouts
      3m 19s
    6. Showing information with data grid enhancements
      5m 1s
    7. Informing users with Confirm Alert and Prompt dialog boxes
      3m 48s
  10. 9m 8s
    1. Accessing IMAP accounts
      6m 31s
    2. Working with the new array functions
      2m 37s
  11. 15s
    1. Goodbye
      15s

Start your free trial now, and begin learning software, business and creative skills—anytime, anywhere—with video instruction from recognized industry experts.

Start Your Free Trial Now
please wait ...
Watch the Online Video Course ColdFusion 9 New Features
2h 40m Intermediate Oct 05, 2009

Viewers: in countries Watching now:

In ColdFusion 9 New Features, author and developer Dan Short has gathered together the important updates and improvements in this dynamic web application. Dan showcases the new ColdFusion Builder application throughout the course, using it to work through the new language and CFScript enhancements in this release. He shows how to use the new Server Manager to compare servers and create server groups, as well as monitor server health through notifications. He also explains the new integration with Office applications, building Excel, Word, and even PowerPoint files on the fly from ColdFusion. Finally, he covers the important new Object Relational Mapping feature and how to use the built-in Flash Player. Exercise files accompany this course.

Topics include:
  • Using new implicit Getters and Setters in ColdFusion Builder
  • Utilizing RAM disks using VFS
  • Managing the system cache to boost site/application performance
  • Learning the new ternary and chained operations
  • Loading detailed Google maps with markers and notations onto a web page
Subjects:
Developer Web
Software:
ColdFusion
Author:
Daniel Short

Defining table relationships

So far we've been dealing with a single object at a time. But in the application world you never have objects that act in isolation. The key to any good application is how it handles related bits of information, using links between tables. In this video we are going to cover how to define foreign key relationships between your objects and how those objects get returned to you when pulling the entities out of the database. So in Chapter5 open up tablerelationships.cfm. Like before, all we are doing is loading a single entity and dumping it out to the screen.

All of our work in this case is going to be done inside of our cfcs. So in order to define relationships, we need to have two things to relate to each right other. Right now we only have an Artist.cfc. Let's create the art component, so I can relate artist and art to each other. In the cfcs folder, right- click and choose New and File. We'll name the file Art.cfc and click Finish. Inside here we'll say cfcomponent persistent = true and that's all we need for our Art.cfc.

Now, you'll notice that I did not specify the table property of the cfcomponent tag. If the component has the exact same name as the table ColdFusion will assume that that's the one you want to be persistent against. So as you see here, Art.cfc has the same name as the Art table. For Artists, the table is named Artists plural but the object is singular. That's why we had to specify the table property of the cfcomponent tag. So let's go ahead and open up Artist.cfc, and we'll declare the relationship in between these two tables.

That's done using the cfproperty tag. So, on the cfproperty tag, I am going to say that the name of this property is Art and I'll specify the fieldtype. In this case, we have a one-to-many relationship. There's one artist to many art pieces. Then I'll specify which key I want to use as the foreign key in the Art table, and in that case it's ArtistID. Next, I need to specify the object that defines the related records.

So I need to specify the cfc Art as the object that is related to Artists. And lastly I'll tell it how I want these related records returned. In this case I want them returned in an array. So when I ask for the art pieces for this artist, I'll get an array of art objects back. We'll save this record, go back to table relationships.cfm, and preview our file, and we get an error. The reason we get an error is because now that I have defined one property for the object, I now need to define all properties that I want to be available.

So let's go back to the Artist object, and we'll define a few more properties. First I need to define the primary key for this particular object, and in that case it's ArtistID. The way I tell it that this is the unique ID for this particular table is I say unique = true, and then that will serve as the primary key for this record. Now I'll specify just a few more properties, so we have something to look at in our examples, but I am not going to define them all because it's not really relevant to how all of this works.

So now I have my Firstname, Lastname, ArtistID and a collection of Art objects. Let's go back to tablerelationship.cfm and reload our page. Now we see I have my ArtistID, Firstname, Lastname and an array of Art objects. If I scroll down here, I can see I have 1, 2, 3, 4, 5 different art pieces, associated with this particular artist. And if I look down here in the Console, I can see that it has run two distinct select statements for me.

The first one defines the Artist ID, Firstname and Lastname. The second select statement shows me all of the art pieces that are assigned with that particular artist. Giving the art pieces back as an array of objects is okay but it's kind of hard to pick out individual art pieces that I want to take a look at or use on my pages. The reason it is difficult to find what I am looking for was an array is I would need to loop through and find the art piece that I would want, and then pull it out and use it. But I can change the way my art pieces get returned to me.

If I go back to the Artist object, I can change my type to struct, and specify I one additional property, which is structkeycolumn, and I'll say I want to use the Art ID as the key column in my structure of art pieces. If I go back to tablerelationships.cfm, I'll reload my page, and now instead of an array I get a struct with the ID as the key column in the structure. So if I wanted to reference Art ID number two, I can say artist.getart and grab the structure with a key of two to get my proper art piece back.

So now that you know how to relate all of your database records, you are ready to go out into the world and can play with ColdFusion 9's new ORM functionality.

There are currently no FAQs about ColdFusion 9 New Features.

 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now Already a member? Log in

* Estimated file size

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed ColdFusion 9 New Features.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

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.

Sign up and receive emails about lynda.com and our online training library:

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

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.