RE: ORM Compositie Key Help
Noob mistake. I had this.ormsettings.flushAtRequestEnd set to flase in applicaiton.cfc and was not using ormFlush() after entitySave. I Must have changed it to false to try an example in John W's book or something. .:.:.:.:.:.:.:.:.:.:.:. Bobby Hartsfield http://acoderslife.com http://cf4em.com -Original Message- From: Bobby Hartsfield [mailto:bo...@acoderslife.com] Sent: Sunday, January 08, 2012 8:42 PM To: cf-talk Subject: RE: ORM Compositie Key Help So my issue may not be related to composite keys at all... If I use a generator of any type other than native, I get the issue of no records. I created this small example to prove it: The component: states.cfc component persistent=true table=tblStates { property name=StateId ormtype=string length=33 fieldtype=id generator=assigned; property name=stateCode ormtype=string length=2; property name=stateName ormtype=string length=30; } CFM Template to call states component: statesTest.cfm == cfscript stateCodes = AL,HI,FL,NC,NY,NE,KS; stateNames = Alabama,Hawaii,Florida,North Carolina,New York,Nevada,Kansas; for (i=1; i lte listlen(stateCodes); i=i+1) { obj = EntityNew(states); obj.setStateCode(listgetat(stateCodes, i)); obj.setStateName(listgetat(stateNames, i)); obj.setStateID(obj.getStateCode() _ replace(obj.getStateName(), '[^\w]', '_', 'all')); entitySave(obj); } /cfscript If I call statesTest.cfm, It will create tblStates as expected, but it will not put anything in it. If I profile the database when I run statesTest.cfm, all queries are selects... no inserts. Now... If I change the stateID property in states.cfc to the following: property name=StateId fieldtype=id generator=native; ...and remove the obj.setStateID() line from statesTest.cfm, it inserts the records fine. Any ideas while I still have hair left? Thanks! .:.:.:.:.:.:.:.:.:.:.:. Bobby Hartsfield http://acoderslife.com http://cf4em.com -Original Message- From: Bobby Hartsfield [mailto:bo...@acoderslife.com] Sent: Sunday, January 08, 2012 3:09 PM To: cf-talk Subject: RE: ORM Compositie Key Help FYI, I did read people saying to set the generator of composite keys to assigned (even though I'm pretty sure that is the default) so I did try that but it did not make a difference. .:.:.:.:.:.:.:.:.:.:.:. Bobby Hartsfield http://acoderslife.com http://cf4em.com -Original Message- From: Bobby Hartsfield [mailto:bo...@acoderslife.com] Sent: Sunday, January 08, 2012 1:40 PM To: cf-talk Subject: ORM Compositie Key Help Hi All, I'm still playing around with ORM and am finally trying to use it in an actual project but am running into an issue with composite keys. Here is a basic compnent that works. component persistent=true table=tmp_utilities_import { property name=stateID fieldtype=id generator=native; property name=stateCode ormtype=stringlength=2; property name=stateName ormtype=stringlength=30; property name=RECORDTIMESTAMP ormtype=timestamp default=; any function init() { variables.recordTimeStamp = now(); } } I have an excel doc full of records that I read in and loop over. Using the above component, I can use the generated setters to set the values and then use entitySave() to write it to the database. The problem comes when I try to make stateCode (which is just the two letter state abbreviation) and stateNamepart of the PK. I change the above to: == component persistent=true table=tmp_utilities_import { property name=stateID fieldtype=id generator=native; property name=stateCode fieldtype=id ormtype=string length=2; property name=stateName fieldtype=id ormtype=string length=30; property name=RECORDTIMESTAMP ormtype=timestamp default=; any function init() { variables.recordTimeStamp = now(); } } == Then I use the same code to loop over the spreadsheet. There is no error but it does not write anything to the database either. When I run profiler (this is SQL Server 2005 by the way), I see the inserts with the first entity but I only see a bunch of selects with the second. I drop the table each time I run it so I know its empty to begin with. Both components create the table as I would expect them to (correct columns, types and constraints). I'm sure I'm doing something wrong obviously but I can't seem to find what that is. Any ideas here? Thanks. .:.:.:.:.:.:.:.:.:.:.:. Bobby Hartsfield http://acoderslife.com http://cf4em.com
RE: ORM Compositie Key Help
FYI, I did read people saying to set the generator of composite keys to assigned (even though I'm pretty sure that is the default) so I did try that but it did not make a difference. .:.:.:.:.:.:.:.:.:.:.:. Bobby Hartsfield http://acoderslife.com http://cf4em.com -Original Message- From: Bobby Hartsfield [mailto:bo...@acoderslife.com] Sent: Sunday, January 08, 2012 1:40 PM To: cf-talk Subject: ORM Compositie Key Help Hi All, I'm still playing around with ORM and am finally trying to use it in an actual project but am running into an issue with composite keys. Here is a basic compnent that works. component persistent=true table=tmp_utilities_import { property name=stateID fieldtype=id generator=native; property name=stateCode ormtype=stringlength=2; property name=stateName ormtype=stringlength=30; property name=RECORDTIMESTAMP ormtype=timestamp default=; any function init() { variables.recordTimeStamp = now(); } } I have an excel doc full of records that I read in and loop over. Using the above component, I can use the generated setters to set the values and then use entitySave() to write it to the database. The problem comes when I try to make stateCode (which is just the two letter state abbreviation) and stateNamepart of the PK. I change the above to: == component persistent=true table=tmp_utilities_import { property name=stateID fieldtype=id generator=native; property name=stateCode fieldtype=id ormtype=string length=2; property name=stateName fieldtype=id ormtype=string length=30; property name=RECORDTIMESTAMP ormtype=timestamp default=; any function init() { variables.recordTimeStamp = now(); } } == Then I use the same code to loop over the spreadsheet. There is no error but it does not write anything to the database either. When I run profiler (this is SQL Server 2005 by the way), I see the inserts with the first entity but I only see a bunch of selects with the second. I drop the table each time I run it so I know its empty to begin with. Both components create the table as I would expect them to (correct columns, types and constraints). I'm sure I'm doing something wrong obviously but I can't seem to find what that is. Any ideas here? Thanks. .:.:.:.:.:.:.:.:.:.:.:. Bobby Hartsfield http://acoderslife.com http://cf4em.com ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:349350 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
RE: ORM Compositie Key Help
So my issue may not be related to composite keys at all... If I use a generator of any type other than native, I get the issue of no records. I created this small example to prove it: The component: states.cfc component persistent=true table=tblStates { property name=StateId ormtype=string length=33 fieldtype=id generator=assigned; property name=stateCode ormtype=string length=2; property name=stateName ormtype=string length=30; } CFM Template to call states component: statesTest.cfm == cfscript stateCodes = AL,HI,FL,NC,NY,NE,KS; stateNames = Alabama,Hawaii,Florida,North Carolina,New York,Nevada,Kansas; for (i=1; i lte listlen(stateCodes); i=i+1) { obj = EntityNew(states); obj.setStateCode(listgetat(stateCodes, i)); obj.setStateName(listgetat(stateNames, i)); obj.setStateID(obj.getStateCode() _ replace(obj.getStateName(), '[^\w]', '_', 'all')); entitySave(obj); } /cfscript If I call statesTest.cfm, It will create tblStates as expected, but it will not put anything in it. If I profile the database when I run statesTest.cfm, all queries are selects... no inserts. Now... If I change the stateID property in states.cfc to the following: property name=StateId fieldtype=id generator=native; ...and remove the obj.setStateID() line from statesTest.cfm, it inserts the records fine. Any ideas while I still have hair left? Thanks! .:.:.:.:.:.:.:.:.:.:.:. Bobby Hartsfield http://acoderslife.com http://cf4em.com -Original Message- From: Bobby Hartsfield [mailto:bo...@acoderslife.com] Sent: Sunday, January 08, 2012 3:09 PM To: cf-talk Subject: RE: ORM Compositie Key Help FYI, I did read people saying to set the generator of composite keys to assigned (even though I'm pretty sure that is the default) so I did try that but it did not make a difference. .:.:.:.:.:.:.:.:.:.:.:. Bobby Hartsfield http://acoderslife.com http://cf4em.com -Original Message- From: Bobby Hartsfield [mailto:bo...@acoderslife.com] Sent: Sunday, January 08, 2012 1:40 PM To: cf-talk Subject: ORM Compositie Key Help Hi All, I'm still playing around with ORM and am finally trying to use it in an actual project but am running into an issue with composite keys. Here is a basic compnent that works. component persistent=true table=tmp_utilities_import { property name=stateID fieldtype=id generator=native; property name=stateCode ormtype=stringlength=2; property name=stateName ormtype=stringlength=30; property name=RECORDTIMESTAMP ormtype=timestamp default=; any function init() { variables.recordTimeStamp = now(); } } I have an excel doc full of records that I read in and loop over. Using the above component, I can use the generated setters to set the values and then use entitySave() to write it to the database. The problem comes when I try to make stateCode (which is just the two letter state abbreviation) and stateNamepart of the PK. I change the above to: == component persistent=true table=tmp_utilities_import { property name=stateID fieldtype=id generator=native; property name=stateCode fieldtype=id ormtype=string length=2; property name=stateName fieldtype=id ormtype=string length=30; property name=RECORDTIMESTAMP ormtype=timestamp default=; any function init() { variables.recordTimeStamp = now(); } } == Then I use the same code to loop over the spreadsheet. There is no error but it does not write anything to the database either. When I run profiler (this is SQL Server 2005 by the way), I see the inserts with the first entity but I only see a bunch of selects with the second. I drop the table each time I run it so I know its empty to begin with. Both components create the table as I would expect them to (correct columns, types and constraints). I'm sure I'm doing something wrong obviously but I can't seem to find what that is. Any ideas here? Thanks. .:.:.:.:.:.:.:.:.:.:.:. Bobby Hartsfield http://acoderslife.com http://cf4em.com ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:349351 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm