Before starting on the advanced topics, I thought it will be better to build some ground and hence I decided to do a post on the ORM basics. In this post, we will build a simple example to get a taste of ColdFusion ORM (CF-ORM) and during that we will also understand some of the basic concepts.
ORM is object relational mapping and in ColdFusion, objects are created using CFC. CFCs that needs to be persisted are called persistent CFC and that is marked by setting ‘persistent’ attribute to true on the component. We also need to define what persistent fields will be there in a persistent CFC and that is defined using ‘cfproperty’. A field/property is marked persistent by setting persistent attribute to true on the cfproperty. By default, if the CFC is persistent, all its properties are considered as persistent unless you mark a property non-persistent. So typically ‘persistent’ attribute on the property is used only when you need to make that property non-persistent.
Each persistent CFC in ColdFusion application maps to a table in the database and each property in the persistent CFC maps to a column in the table (not exactly true but we will come to that later.. For the time being lets keep it that way). We will use the cfartgallery datasource for this example which has Artists and Art tables.
The first thing you need to do is – enable ORM for the application and define a datasource to be used (What is an ORM without a datasource?). ColdFusion ORM uses Application.cfc to define all the ORM specific settings. (If you haven’t started using Application.cfc for your application, its time to start using it!)
Application.cfc
Component { this.name="ArtGallery"; this.ormenabled="true"; this.datasource="cfartgallery"; }
Note that the datasource setting defined here makes it the default datasource of your application which can be used by tags like cfquery, cfinsert, cfupdate, cfdbinfo. The same default datasource will be used by ORM as well.
There are a whole bunch of ORM related configuration that you can do in application.cfc which you can refer here.
Now that the application is configured, let us build the object and define the persistence information on it. To start with, we will first define the Artist.cfc
Artists.cfc
/** * @persistent */ Component { property name="artistid" generator="increment"; property firstname; property lastname; property address; property city; property state; property postalcode; property email; property phone; property fax; property thepassword; }
This is the most simplistic definition of the component where we have defined only the component and its properties names. Since the table for this CFC already exists in the database, we have not added any table specific information in this and we will let ORM infer all the information from the database. The only additional setting that we have added here is the ‘generator’ attribute which is used to auto-generate the primary key.
After the components are defined, the first request to this application (i.e a page in this application) will make CF-ORM do all the setup necessary (basically generation of hibernate configuration, mapping files, building the session factory etc). Once the setup is done, you are all set to work with the entities.
We will first list all the artists and here is what you need to do for that
listAll.cfm
<cfscript> artists = EntityLoad("Artists"); writedump(artists); </cfscript>
To load a particular Artists with its ID, here is what you do
list.cfm
<cfscript> artist = EntityLoadByPK("Artists", 1); writedump(artist); </cfscript>
There are several flavors of EntityLoad functions details of which can be read here
Let us now see how to perform insert and update on it.
save.cfm
1 2 3 4 5 6 7 8 9 10 11 | <cfscript><br> // Insert a new artist artist = new Artists(); artist.setfirstname("Leonardo"); artist.setlastname("Da vinci"); artist.setcity("Paris"); EntitySave(artist); writeOutput(artist.getartistid());// Update an artist artist = EntityLoadByPK("Artists", 2); artist.setcity("NewYork"); // artist is automatically updated. </cfscript> |
As we see in the above example, EntitySave is used to insert/update an object in the table. There are some important things to note here
- EntitySave is an intelligent function which automatically finds if a new row needs to be inserted for the given object or whether an existing row needs to be updated.
- We called EntitySave for the insert here but not for update but even then artist ’2′ gets updated. So how did that happen? Actually what happens here is when you load an artist object, it becomes associated with the hibernate session which keeps track of any changes in the object and automatically saves it when the session is flushed. We will talk about more about hibernate session in a later post. For the time being lets just say that Hibernate Session is a short-lived object that represents a conversation between the application and the persistence layer and also acts as the first level of cache.
- We did not write any setter or getter method for artist’s properties in Artists.cfc but we are calling them here. That works because ColdFusion 9 automatically generates accessor methods for any property written in a CFC. More details on generated methods in a later post.
- At line no 6, we called entitySave, but if you check the database, the row is not inserted yet. So when does that happen? Hibernate batches up all the operations till the end of the request or to be exact till hibernate session is flushed. ColdFusion ORM starts up a session when the first ORM method is called in the request and is automatically flushed when the request ends. The batching is done for performance reason so that hibernate executes the sql with the final state of the objects. It will be a huge performance bottleneck if ORM keeps executing sql for each changes in the object.
To delete an Artist, you need to call EntityDelete() passing the object to be deleted.
delete.cfm
<cfscript> artist = EntityLoadByPK("Artists", 15, true); EntityDelete(artist); </cfscript>
Relationship
So far we have seen how to perform CRUD for a single entity. But in any application, there will be entities which are associated and ORM must load the associated object as well when loading a particular entity. For our example, an Art will have an Artist and when loading the art object, it should also load the associated artist. So lets build the model first after which we will see how to work with the association.
In cfartgallery, the table Artists has a one-to-many relationship with Art table, which are joined using the foreign key column ARTISTSID. This means that each artist has created multiple arts and each art is created by one artist. To represent this in the object model, each ARTIST object would contain an array of ART objects. Each ART object will also contain a reference to its ARTIST object thereby forming a bidirectional relation.
To achieve this, we will need to add an extra property ‘arts’ to ‘Artists’ that contains an array of ART objects for that Artist. The modified Artists.cfc would look like
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | /** * @persistent */ Component { property name="artistid" generator="increment"; property firstname; property lastname; property address; property city; property state; property postalcode; property email; property phone; property fax; property thepassword; property name="arts" fieldtype="one-to-many" fkcolumn="artistid" cfc="Art" cascade="all" inverse="true"; } |
Here is the Art.cfc
1 2 3 4 5 6 7 8 9 10 11 12 | /** * @persistent */ Component { property name="artid" generator="increment"; property artname; property price; property largeimage; property mediaid; property issold; property name="artist" fieldtype="many-to-one" fkcolumn="artistid" cfc="Artists" ; } |
Notice the artist property above which is of many-to-one type. Also notice that both the property use the same value for fkcolumn attribute i.e ‘artistid’ of Art table that references artistID pk of Artist table.
Since we have added a new persistent CFC (Art.cfc) after the application was loaded, we need to re-initialize the ORM for this application so that mappings for Art.cfc also gets generated. This can be done by calling ORMReload() method. There are some nice ways to do this but for the time being lets keep it simple by putting this in a separate page which we will call to reload ORM.
initializeORM.cfm
<cfset ormReload()>If you load and dump Artist (using listAll.cfm), you should also see the associated art objects for artists.
Now let us create a new Art and associate it with an existing Artist.
artCreate.cfm
1 2 3 4 5 6 7 8 9 10 | <cfscript> artist = EntityLoad("artists", 1 ,"true"); art = new Art(); art.setartname("landscape"); art.setPrice(1500); art.setissold(false); art.setartist(artist); artist.addArts(art); EntitySave(art); </cfscript> |
If you notice line 7-8 above, we associate artist to art by calling art.setArtist(artist) as well as art to artist by calling artist.addArts(art). Hibernate needs us to do this in order to set up the bidirectional relation properly. Since it is a bidirectional relation, you must also decide which side will set the relation in the database. i.e which side of the relation will set the fkcolumn in the table. This is controlled by the “inverse” attribute of proeprty, which if set to true, tells hibernate that this is a inverse of the other relation and this side of relation should be ignored for persistance. If you don’t set inverse to true, Hibernate will unnecessarily fire two sqls for the same association.
So there you have it. We have seen how you can use ORM to perform the basic CRUD operations on entities. For more details, you can refer to the ORM doc and Hibernate docs.

#1 by John Whish on July 17th, 2009
| Quote
Hi Rupesh, I noticed you’re using EntityLoadByPK in your code, I can’t see it in the CF9 docs. Am I right in thinking that EntityLoad(“artists”, 1 ,”true”) is the same as EntityLoadByPK(“artists”, 1)? Thanks.
#2 by Rupesh Kumar on July 17th, 2009
| Quote
I was waiting for someone to notice this
Yes, EntityLoad(”artists”, 1 ,”true”) is same as EntityLoadByPK(”artists”, 1)
This method was added because it always gives the object right back and you don’t have to pass the boolean parameter. however it was not documented because it was felt that people don’t need to know an extra method which does the exact same thing.
#3 by James Netherton on July 20th, 2009
| Quote
Haven’t reported this to Adobe but I ran into a weird problem testing the ORM stuff. I’m running Ubuntu 9.04 and have deployed CF 9 as a WAR under tomcat 6.
When calling EntityLoad I noticed the page execution would suddenly stop. Looked at the server logs and noticed lots of java.lang.NoClassDefFoundError: javax/transaction/Synchronization exceptions.
Had to manually add jta.jar into the lib directory. Looked inside the WAR file and jta.jar didn’t seem to be packaged, presumably it should be?
#4 by Rupesh Kumar on July 27th, 2009
| Quote
@James, we don’t package this because we assume that jta classes will be available on all the application servers we support.
Tomcat is not an application server and is just a servlet container. Hence it does not contain these classes. You would need to include jta.jar in the classpath as you did. Ant btw, ColdFusion does not officially support tomcat. So we have never tested ORM on tomcat.
#5 by Tony Nelson on August 3rd, 2009
| Quote
Is there any way to have Hibernate automatically trim the property values before saving to the database?
For example, if you had:
art = new Art();
art.setartname(” landscape “);
EntitySave(art);
it would insert just “landscape”?
Or if you had:
art = new Art();
art.setartname(“”);
EntitySave(art);
It would insert NULL rather than an empty string?
#6 by Rupesh Kumar on August 3rd, 2009
| Quote
ORM respects whatever value you set in the object. ORM should not trim the values or it should not convert empty string to null blindly. Doing these sort of things can throw up lot of surprises in your application.
However there is definitely a way for you to do that in a central place for your entire application using event Handler. In the event handler, in preInsert and preUpdate methods, you can take check the values – you can trim it there and if it is empty string, you can set it to null.
#7 by Tony Nelson on August 4th, 2009
| Quote
That makes sense, although I was hoping there might be a way to set something like this.ormSettings.trimProperties = true.
I was able to trim all the values using a global event handler, but how would I set a value to null? Here’s what my preInsert looks like right now:
Does that look right? Is there a better way I could be writing it? Also, I’m a little worried about performance.
On a side note, it would be really nice to be able to do arguments.entity["set#property.name#"](trim(value)), but that’s a little wishful thinking
#8 by Tony Nelson on August 4th, 2009
| Quote
Looks like my code didnt’ come through. Let’s try that again…
<cffunction name="preInsert" access="public" returntype="void">
<cfargument name="entity" type="any" />
<cfset var properties = getMetaData(arguments.entity).properties />
<cfset var property = "" />
<cfset var value = "" />
<cfloop array="#properties#" index="property">
<cfinvoke component="#arguments.entity#" method="get#property.name#" returnvariable="value" />
<cfif !isNull(value)>
<cfinvoke component="#arguments.entity#" method="set#property.name#">
<cfinvokeargument name="1" value="#trim(value)#" />
</cfinvoke>
</cfif>
</cfloop>
</cffunction>
#9 by Rupesh Kumar on August 4th, 2009
| Quote
You know what, I think it is not a good idea to use event handler for this purpose. This will indeed be expensive. I think you should take care to trim/validate when you set the value on the object.
These kind of things should be done by the application and not the framework. So lets say, you get the input data from form, you can trim it right there and then set it on the object.
#10 by Tony Nelson on August 5th, 2009
| Quote
I agree, especially considering a lot of frameworks already combine the form/url scopes into a shared request context object, which could easily be trimmed.
Aside from that, is there any way to have Hibernate save empty strings as NULL rather than ”?
#11 by Rico Suave on August 18th, 2009
| Quote
I’m wondering why the object property-values are set with methods rather than with properties, so why not:
art.artname = “landscape”;
instead of:
art.setartname(“landscape”);
IMHO the former syntax makes more sense.
#12 by david buhler on August 18th, 2009
| Quote
I can’t actually get the child entity to populate with the query of the first entity. It did work, and then I changed something, and now the second entity is never shown.
I have a Person object.
I want to add an Address to the Person.
When I request people, I want to see each of their addresses.
Here’s my code:
Address.cfc
Person.cfc
SaveUser.cfm
person = new Person();
address = new Address();
address.setAddress_1(‘address 1′);
address.setAddress_2(‘address 2′);
address.setCity(‘city name’);
address.setZip(12345);
//person.setAddress(address);
address.setPerson(person);
person.setEmail(‘person@acme.com’);
person.setPassword(‘catcat’);
EntitySave(person);
// — FLUSH
ORMFlush();
peopleList = EntityLoad(“person”);
#13 by david buhler on August 18th, 2009
| Quote
I posted the code complete at: http://snipt.org/lnoh
#14 by Rupesh Kumar on August 18th, 2009
| Quote
I don’t see any relationship definition here in these two cfc. So, this code would not have established the relation between Person and address in the database. Also, ORM will not have any way to load and associate the Address Object when you load Person.
You need to define the relationship metadata on the address property of Person and similarly on the person property of Address.
#15 by Darrin on October 13th, 2009
| Quote
I am having a issue with ORM, I have a user, and address table so a user can have many address’s. I can not get teh address to insert with a user id, I can not get any data at all in the address table.
here is my code:
component persistent=”true” output=”false”
{
property name=”IDUser” fieldtype=”id” generator=”native” type=”numeric” default=”0″ ormtype=”integer” notnull=”true”;
property name=”Name” ormtype=”string”;
property name=”Email” ormtype=”string” ;
property name=”Addresss” cfc=”address” fieldtype=”one-to-many” fkcolumn=”user” cascade=”all” inverse=”true”;
}
/**
* @persistent
*/
component
{
property name=”addressID” fieldtype=”id” generator=”native” type=”numeric” default=”0″ ormtype=”integer” notnull=”true”;
property string address1;
property string address2;
property string city;
property string state;
property string zip;
property name=”user” cfc=”user” fieldtype=”many-to-one” fkcolumn=”IDUser”;
}
// create a new user
User1 = EntityNew( “User” );
// set properties
User1.setName( ‘xxx’ );
User1.setEmail( ‘xxx@d.com’ );
EntitySave( User1, True );
writeOutput(User1.getIDUser());
Adddres1 = EntityNew( “address” );
Adddres1.setAddress1( “PSC 46″ );
Adddres1.setAddress2( “Box 146″ );
Adddres1.setCity( “APO” );
Adddres1.setState( “AE” );
Adddres1.setZip( “09456″ );
// save the new user
User1.addAddresss( Adddres1 );
EntitySave( Adddres1, true );
#16 by Rupesh Kumar on October 13th, 2009
| Quote
Hi Darrin,
I see couple of issues here.
1. In User.cfc, the fkcolumn value for the Address property should be “IDUser” which is the fkcolumn in Address table.
2. For relationship, You need to set the relationship properly. you need to set the user on address by calling User1.setAddress(address1) before calling entitysave on address1.
Alternatively you need to call EntitySave(User1) after calling user1.addAddress(address1)
#17 by Jim on February 19th, 2010
| Quote
How do you pass null values from a Flex VO that is bound to the Coldfusion ORM CFC? For instance if I have a numeric field in the database that has null values, I have no problem retrieving a row of data into a Coldfusion CFC then to Flex, even if the value for the numeric is null. But when I try passing a null value for that numeric back to Coldfusion, it ends up trying to save it as a “0″, which is not at all what I want. I tried setting required=”false” with no luck.
I also end up with validation errors on dates where type=”date” for the column property when I try passing a null or an empty string from Flex to Coldfusion, I need to be able to save a null for the date column. The same thing happens when I have validate=”email” for a column, it complains if I try passing a null value from Flex to the Coldfusion ORM CFC. Thanks for any help. For now I have written my own validation routine that can validate emails, dates, etc. and checks if there is an empty value for a property. But I have to set my dates to the “Any” data type to get around this.
Thanks for any help.
#18 by Rupesh Kumar on February 19th, 2010
| Quote
Jim,
This is something that came up recently and we are evaluating it currently. The validator in CF skips the validation if the property value is null. However when the object is coming over from flex to CF, the translation layer converts the null value to empty string (for string)or ’0′ (for int). There is no way currently, to tell the translation layer to skip this conversion.
We would try to get this fixed ASAP, but until then, the only workaround is – In all the service methods that is called by flex, change these empty string or “0″ back to null using javacast.
#19 by Jim on February 19th, 2010
| Quote
Is it possible to use coldfusion mappings in the cfc attribute of cfproperty when defining relationships in a CFC ORM object? It doesn’t seem to be possible as I was getting errors until I used the full path from the web root, rather than using a Coldfusion mapping.
#20 by Rupesh Kumar on February 19th, 2010
| Quote
You can definitely use mappings in the cfc attribute of relationship. The mapping can be server level or application level. CF-ORM just needs the fully qualified cfc name and it uses the same resolution mechanism that is used by createObject. The only thing that you need to take care is that the CFC should have a unique fully qualified name. i.e you should not have two mappings in a way such that the same CFC can have two different fully qualified name.
If it is not working for you, could you please send me the sample CFC and mappings, so that I can take a look?
#21 by Jim on February 22nd, 2010
| Quote
Thanks so much for the replies. Now that I know the mappings are supported, let me play with it a little more to make sure all my code is correct.
I’ll just change those values back to null in my validate routine for now. I look foward to the fix, I’ll check the hot fixes periodically.
#22 by Jim on March 2nd, 2010
| Quote
The mapping seems to be working well now, but I have a couple of other questions that failed to be answered on the Adobe Coldfusion forum.
When you do and EntityLoad, it calls your init function on the CFC if you have one. All well and good, but is there a way to pass parameters to the init function?
Also, is there a way to include properties in your ORM class that are not included when binding to a Flex VO? I used remotingfetch=”false”, which works fine when you are passing the class back to Flex, but it does not work when you are trying to pass the Flex VO to Coldfusion. I also tried persistent=”false” on the Coldfusion CFC property, but no luck.
Thanks.
#23 by Rupesh Kumar on March 3rd, 2010
| Quote
Good to know that the mappings are working fine.
We have clearly documented that the init method of your persistent CFC should have either no arguments or all the arguments should be optional. ColdFusion will always call this method with no-arguments while calling EntityLoad. That is the standard that Hibernate follows that your java bean should have no-argument constructor.
Regarding your last question, if you don’t want the value to be peristed at all, then you can mark the property as non-persistent. However, I am curious to know why would you ever want it?
If you dont want that property to come to the CF side at all, then the only possible way is to have different named properties on the CF side and the flex side so that when the AS object gets converted to CFC, those values will not be set to any persistent property. however those values will then go under ‘THIS’ scope of the CFC.
#24 by Jim on March 3rd, 2010
| Quote
It wasn’t a question of whether or not I wanted it persisted (I do) but how to maintain data within the CFC that I did not want to pass back and forth to Flex. This might be items within the CFC that I want to keep track of that are not in the database, such as whether a value came in null from the database or not.
Thanks again for the reply.
#25 by BryonSR on March 9th, 2010
| Quote
Hello.
I have a similar issue to Jim’s, when testing the upgrade from CF8 to CF9 for our business environment. In one scenario, I pass a null array – as a property of an object – from Flex to CF, and the array gets converted to an empty string by the serialization process. This, of course, results in a type mismatch when I try to pass the object back to Flex.
It would be a pain to go through our code and add setters to everything, especially as they would have to accept “ANY” as a parameter to get around the empty string, which doesn’t feel like a good practice.
Any recommendations? Wait for a patch?
#26 by Rupesh Kumar on March 26th, 2010
| Quote
@Bryon, Sorry for replying late as I was out of station.
We know there is an issue when null gets converted to empty string during serialization but it has been like this in CF8 as well. It should not affected your application while upgrading to CF9. Could you provide some more details what exactly broke during upgrade? If you want, you can mail it to me at rukumar at adobe dot com
#27 by Simon on March 18th, 2010
| Quote
Hi Rupesh,
Maybe you could help me on this problem:
I have an issue when trying to send an object from Flex back to CF – HB ORM. This error message occur when I use entitysave:
“[RPC Fault faultString="Error deserializing client message." faultCode="Client.Packet.Encoding" faultDetail="null"]”
The error doesn’t occur (and my user object get persisted in the database) if I delete his many-to-one realtion:
But of course I want to keep it…
I don’t have any other ideas of what’s going on ! Do you ?
Thanks
Simon
#28 by Rupesh Kumar on March 26th, 2010
| Quote
@Simon,
This error message is not very helpful. I would like to know the exact error that was thrown from the server side.
Could you check the error message from the exception logs and post that?
#29 by Simon on March 18th, 2010
| Quote
Hello again…
Actually it may be a problem with the alias… do you know if there is a difference between how CF8 and CF9 manage the alias ? any configuration to do in CF administrator ?
Did you experience any trouble in sending object back and forth from flex to cf-persistent component ?
Thanks
#30 by Rupesh Kumar on March 26th, 2010
| Quote
My guess would be – you are using application mapping and new flex remoting. The new flex remoting in CF9 does not support the application mapping, which means that the CFC name in the alias of AS classes should be the fully qualified name of the CFC and it must be either in the webroot or in CF’s wwwroot.
If you need to use the application mapping with flex remoting, you can switch to the old remoting. An easy way to do that would be to replace the flex related config xmls in CF9 with the same in CF8.
Rupesh
#31 by Mark on November 4th, 2010
| Quote
By the way, this feature (fully qualified path = alias) is absolutely horrific when it comes to reusability of components. Your only option is to stick your cfcs in the wwwroot if you want to use the same cfc in multiple apps? No fun. Need to have a much more flexible alias methodology when it comes to flash remoting.
#32 by Simon Lenoir @ Sydney, Australia on March 29th, 2010
| Quote
Thanks for your answer Rupesh. You were right about the alias. Now I’m using Flash Builder Data Services, and most of the code is generated for me based on CF Services… that’s great !
Hibernate with ColdFusion for Fhash Remoting is very exiting and state-of-the -art programming !
However I’m running now into the empty array converted to string issue (@Byron)… I guess that it will always happens when an entity.cfc has a one-to-many relations (the one to many relation is an array). As an example ONE Department has Many employees, the Deparment.cfc look like that:
component persistent=”true” table=”department” output=”false” {
property name=”dep_id” column=”dep_id” type=”numeric” ormtype=”int” fieldtype=”id”;
property name=”dep_name” column=”name” type=”string” ormtype=”string”;
property name=”employees” fieldtype=”one-to-many” fkcolumn=”dep_id” cfc=”employe” cascade=”all-delete-orphan”;
If I loadentity the department 1, change his name string property in flex (“IT Department” to “Sales”), and return the result to coldfusion: CF try to deserialize the department, found and empty string employees that should be a null array and display the error message (before entitySave get called)
I didn’t try yet but I guess it has to be handled in Flex, to make sure that an array return as an array… so I guess I should overwrite some action script code generated by flex data services.
Do you think I’m on the good tracks ?
Error Message:
rg.hibernate.HibernateException: coldfusion.runtime.NonArrayException: Object of type class java.lang.String cannot be used as an array
Unable to invoke CFC – coldfusion.runtime.NonArrayException: Object of type class java.lang.String cannot be used as an array
Root cause
#33 by Don on May 27th, 2010
| Quote
How do I do something like get an artist by last name?
#34 by Rupesh Kumar on May 31st, 2010
| Quote
Couple of options
- EntityLoad(‘Artist’, {lastName=”blahblah”});
- ORMExecuteQuery(“from Artist where lastName=?”, [lastName]);
Check the documents for EntityLoad and ORMExecuteQuery.
#35 by Shawn on June 8th, 2010
| Quote
Hi Rupesh,
Quick question…. if I have the one-to-many mappings done with inverse set on the child object in the parent, shouldn’t I just be able to do an entitysave on the parent object and let ORM take care of saving the children objects ? Or do I have to save each child entity separately ?
For example…
cust = EntityNew(“Customer”);
cust.firstname =’Ted’;
cust.lastname=”Williams’;
item1=EntityNew(“Item”);
item1.name=’boots’;
item1.setCust(cust);
cust.addItem(item1);
item2=EntityNew(“Item”);
item2.name=’hat’;
item2.setCust(cust);
cust.addItem(item2);
EntitySave(cust);
// Will this persist the cust along with the related items to the database , or do I have to do a seperate entitysave for each item as well ?
#36 by Rupesh Kumar on June 21st, 2010
| Quote
Shawn, sorry for the delay in reply.
If you have set cascade=”save-update” or “all” on the one-to-many relationship, then the EntitySave call on the parent will automatically be cascaded to the child objects. If there is no cascade defined, then you need to call EntitySave on the child objects as well.
p.s : In case you are not aware, there is a google group for CF-ORM at http://groups.google.com/group/cf-orm-dev/ which is quite active and you can ask all your ORM related questions there as well.
#37 by Don on July 2nd, 2010
| Quote
How does ORM handle pivot tables?
I have a table with volunteers, a table of organizations, then a pivot table to match up volunteers to organizations. A volunteer can belong to more than 1 organization.
I’m thinking I have to make an association from volunteers to pivot and pivot to organizations. Should that work so that when I pull up a volunteer I will see all organizations they belong to and if I pull up an organization I will see all volunteers for that org?
#38 by Jim on July 14th, 2010
| Quote
The release notes are out for CF 9.0.1 and it does not seem to include a fix for passing null values from Flex to a CF ORM object that I mentioned Feb. 19, above. Is there a fix for this? Thanks.
#39 by Don on July 23rd, 2010
| Quote
After extensive googling I have come to the conclusion that ORM can not handle pivot tables. Thus I still have to know SQL to work with a database and ORM is rapidly becoming useless to me.
#40 by Jim on July 26th, 2010
| Quote
Don,
It sound like you have a many-to-many relationship with a link table between volunteers and organizations.
I don’t know the details, but this can be accomplished. There is a type of “many-to-many” in your relationship types on the cfproperty tag. Also, there is a linktable attribute that you use. So I’m pretty sure it can handle it, you just have to set it up. Look up many-to-many relationships in the documentation.
#41 by Grietje Goedkoop on February 25th, 2011
| Quote
Hi,
I just started to familiarize myself with ORM and I wonder if you would also use ORM to update a record via a form, for instance in a cms? In all examples I see static update data like “williams” or ” New York” and the same to select a particular record like “ID=2″.
What about updating via a form, like address.setAddress_1(’#form.address_1#′) or “ID=#url.IDofthe record#”
Or maybe I simply don’t understand the functionality of ORM?
#42 by Jason Presley on April 4th, 2011
| Quote
@Rupesh Thank You very much. I have been trying to figure out ORM and was struggling but this broke it down so I was able to get the basic CRUD functionality down.
@Grietje Here is the code that I have in my very simple CRUD app that takes values from a from and updates them via ORM.
HISTORICALEVENTS.CFC
component persistent=”true” table=”HistoricalEvents” {
property name=”EventID” fieldtype=”id” ormtype=”int” generator=”identity”;
property name=”EventDate” ormtype=”date”;
property name=”EventTitle” ormtype=”string” length=250;
property name=”EventLocation” ormtype=”string” length=50;
}
HISTORICALEVENTS.CFM
if(IsDefined(‘url.delid’))
{
event = EntityLoadByPK(“HistoricalEvents”, #url.delid#);
EntityDelete(event);
location(“HistoricalEvents.cfm”, false)
}
else if(IsDefined(‘url.editid’))
{
event = EntityLoadByPK(“HistoricalEvents”, #url.editid#);
isEdit = true;
}
else if(IsDefined(‘form.btnSubmit’))
{
event = new HistoricalEvents();
event.seteventtitle(#form.eventtitle#);
event.seteventlocation(#form.eventlocation#);
event.seteventdate(#form.eventdate#);
EntitySave(event);
location(“HistoricalEvents.cfm”, false)
}
if(isDefined(‘form.eventid’))
{
event = EntityLoadByPK(“HistoricalEvents”, #form.eventid#);
event.setEventTitle(#form.EventTitle#);
event.setEventLocation(#form.EventLocation#);
event.setEventDate(#form.EventDate#);
EntitySave(event);
location(“HistoricalEvents.cfm”, false)
}
ormreload();
Event Title
Event Location
Event Date
#eventtitle#
#eventlocation#
#dateformat(eventdate, “short”)#
Del
Edit
Title: <input type="text" name="EventTitle" value=”#event.getEventTitle()#”>
Location: <input type="text" name="EventLocation" value=”#event.getEventLocation()#”>
Date: <input type="text" name="EventDate" value=”#dateformat(event.getEventDate(), ‘short’)#”>
HOPE THAT HELPS!
#43 by 3d tv on June 7th, 2011
| Quote
What is the handler mapping needed in IIS 7.x to produce CAPTCHA images? The only one that works seems to be the wildcard, which is ridiculous from a security point of view. In tightening the security of ColdFusion according to the lock-down guide at http://www.adobe.com/products/coldfusion/whitepapers/pdf/91025512_cf9_ lockdownguide_wp_ue.pdf, they recommend to remove this wildcard mapping, but that seems to break captcha.