Skip to content

Instantly share code, notes, and snippets.

@thecfguy
Last active August 29, 2015 14:02
Show Gist options
  • Save thecfguy/ba7bcc1a11d49f973114 to your computer and use it in GitHub Desktop.
Save thecfguy/ba7bcc1a11d49f973114 to your computer and use it in GitHub Desktop.
ORM One-To-Many
component output="false" singleton{
// Default Action
property name="masterService" inject="entityService:tmaster" scope="variables";
property name="detailService" inject="entityService:tdetail" scope="variables";
function index(event,rc,prc){
var masterbean = masterService.new({col1:"master"});
var detailbean = detailService.new({col2:"detail"});
/* save with master bean
database operations:
2 insert query and 1 update query
*/
masterbean.addDetail(detailbean);
masterService.save(masterbean);
event.setView("test");
}
}
component displayname="tdetail" output="false" persistent="true" {
property name="id" fieldtype="id" generator="identity";
property name="col2" type="string";
property name="master" fieldtype="many-to-one" cfc="tmaster" fkcolumn="masterid" cascade="all";
}
component displayname="tmaster" output="false" persistent="true" {
property name="id" fieldtype="id" generator="identity";
property name="col1" type="string";
property name="details" type="array" fkcolumn="masterid" fieldtype="one-to-many" cfc="tdetail" cascade="all" singularname="detail";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment