Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
ColdFusion 9's ORM features make it less necessary to spend your days building simple value objects and crud methods, but you still have to spend time typing out repetitive code and dealing with object relationships. Luckily, ColdFusion Builder helps with this as well by providing a feature rich way to build ORM CFCs without writing a line of code. So, we are going to return to our ARTISTS and ART tables and build some ORM CFCs. First off, I am going to delete the ARTISTS files we generated in our last video, so we can start over with the ORM way of doing things.
In my RDS Data view, I am going to select both the ART and the ARTISTS tables. Then I will right-click, choose Adobe CFC Generator > Create ORM CFC. Now, the first dialog is pretty simple. We are just going to choose where we want the CFCs to be generated. We will stick these in our Chapter 7 folder and click OK. Then the next screen may take a bit to come up, because it's using all sorts of Flash forms in ColdFusion 9. So, as we can see, here on the left we have our two tables that I selected, and on the right-hand side, we have all of the columns for the ART tables.
If I select ARTISTS, we will see all of the columns for the ARTISTS table. I can check these boxes to determine which columns I want to actually be in my CFC. So, what we are going to do is build relationships in between the ART and the ARTISTS table. So, I will click on the ART table, and here in the Relationships section, I will click insert. Now I am going to relate the ART table to ARTISTS. I will give it a name and specify my target table, which is ARTISTS, and choose the Multiplicity.
What this means is I am going to choose whether or not there is one piece of art to one artist, one piece of art to multiple artists, multiple pieces of art to a single artist, or whether multiple artists can work on the same piece of artwork. So, I am going to choose multiple pieces of art to one artist, the n-1 relationship. Now, I don't need to choose a Link table, because this is a one-to-one relationship in between the two tables. It's not a many-to-many relationship where I need a intermediary link table. Once I have this relationship defined, I will click Save, select it again, and then I can choose the join conditions.
I need to choose the columns that relate these two tables together. I will scroll down a bit and click insert. Then I need to choose my source field, which in this case, in the ART table is the ARTISTID, and then the target field. In the ARTISTS table, that's also ARTISTID, and click Save. Now I will do the same thing for ARTISTS. I will click insert, choose my relationship name, which will be ART. Choose my target table, also ART. And the Multiplicity. One artist can have multiple pieces of artworks, so it's a 1-n relationship.
Click Save, select the relationship, and we will insert a join condition. My source field is going to be ARTISTID. My target field is also going to be ARTISTID. Click Save. If I scroll down to the bottom, we can click Generate Code. So, it says the code has successfully been generated. I will click Close. Go back to my Chapter 7 folder and refresh. Here, I can see its created an ART, ARTISTS, ARTISTSService, and ARTService.
If I open these up, you will notice in the ART.cfc, at the bottom here it has my ARTISTS property. That shows a many-to-one relationship with the ARTISTS.cfc and specifies my foreign key columns. In my ARTISTSService, I also have methods for creating new artists, deleting artists, getting all artists, a paging method, basically everything we had in the standard CFCs, but using all of the ColdFusion 9 ORM functionality to make it work. So, just like the generated code from the previous video, you can edit the handler that outputs the ORM CFCs' code to suit your needs.
As with this or any extension that generates code, always remember that if you are not happy with the output of the extension, it's worth the time to dig through the handler's directory and get everything customized to suit your specific needs.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 101136 Viewers
61 Video lessons · 87901 Viewers
71 Video lessons · 71778 Viewers
56 Video lessons · 103648 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
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.
Your file was successfully uploaded.