Which version of ColdFusion are you using? Which version of ColdBox are you using? (doubt the later matters but I think it should start being in most questions just in case it helps.)
oCustomer = new testObjects.Customer();
writeDump(oCustomer);
/testObjects/Customer.cfc
/**
Customer
@accessors true
*/
component Customer displayname=“Customer” hint=“This is the Customer Object” output=“false”
{
property name=“ID” type=“numeric” displayname=“Unique ID” hint=“This is the Customers Unique ID”;
property name=“FirstName” type=“string” displayname=“FirstName” hint=“This is the Customers First Name”;
property name=“LastName” type=“string” displayname=“LastName” hint=“This is the Customers LastName”;
property name=“emailAddress” type=“string” displayname=“emailAddress” hint=“This is the Customers emailAddress”;
property name=“address” type=“any” displayname=“address” hint=“This is the Customers address”;
public function init()
displayname=“init” description=“init” output=“false”
{
var oAddress = new testObjects.Address();
setAddress(oAddress);
return this;
}
}
/testObjects/Address.cfc
/**
Address
@accessors true
*/
component Address displayname=“Address” hint=“This is the Address Object” output=“false”
{
property name=“ID” type=“numeric” displayname=“Unique ID” hint=“This is the Address Unique ID”;
property name=“Address1” type=“string” displayname=“Address1” hint=“This is the Address1”;
property name=“Address2” type=“string” displayname=“Address2” hint=“This is the Address2”;
property name=“City” type=“string” displayname=“City” hint=“This is the City”;
property name=“State” type=“string” displayname=“State” hint=“This is the State”;
property name=“Province” type=“string” displayname=“Province” hint=“This is the Province”;
property name=“Country” type=“string” displayname=“Country” hint=“This is the Country”;
public function init()
displayname=“init” description=“init” output=“false”
{
return this;
}
}
Not sure if this is the best way but this is what came to my mind.
oCustomer = new testObjects.Customer();
writeDump(oCustomer);
Customer.cfc
/**
Customer
@accessors true
*/
component Customer displayname=“Customer” hint=“This is the Customer Object” output=“false”
{
property name=“ID” type=“numeric” displayname=“Unique ID” hint=“This is the Customers Unique ID”;
property name=“FirstName” type=“string” displayname=“FirstName” hint=“This is the Customers First Name”;
property name=“LastName” type=“string” displayname=“LastName” hint=“This is the Customers LastName”;
property name=“emailAddress” type=“string” displayname=“emailAddress” hint=“This is the Customers emailAddress”;
property name=“address” type=“any” displayname=“address” hint=“This is the Customers address”;
public function init()
displayname=“init” description=“init” output=“false”
{
var oAddress = new testObjects.Address();
setAddress(oAddress);
return this;
}
}
Address.cfc
/**
Address
@accessors true
*/
component Address displayname=“Address” hint=“This is the Address Object” output=“false”
{
property name=“ID” type=“numeric” displayname=“Unique ID” hint=“This is the Address Unique ID”;
property name=“Address1” type=“string” displayname=“Address1” hint=“This is the Address1”;
property name=“Address2” type=“string” displayname=“Address2” hint=“This is the Address2”;
property name=“City” type=“string” displayname=“City” hint=“This is the City”;
property name=“State” type=“string” displayname=“State” hint=“This is the State”;
property name=“Province” type=“string” displayname=“Province” hint=“This is the Province”;
property name=“Country” type=“string” displayname=“Country” hint=“This is the Country”;
public function init()
displayname=“init” description=“init” output=“false”
{
return this;
}
}
This is the way I would do it. If you cannot get it working I can see if I can come up with a better example inside of ColdBox. This still should work.
oAddress = new testObjects.Address();
oCustomer = new testObjects.Customer(oAddress);
writeDump(oCustomer);
Customer.cfc
/**
Customer
@accessors true
*/
component Customer displayname=“Customer” hint=“This is the Customer Object” output=“false”
{
property name=“ID” type=“numeric” displayname=“Unique ID” hint=“This is the Customers Unique ID”;
property name=“FirstName” type=“string” displayname=“FirstName” hint=“This is the Customers First Name”;
property name=“LastName” type=“string” displayname=“LastName” hint=“This is the Customers LastName”;
property name=“emailAddress” type=“string” displayname=“emailAddress” hint=“This is the Customers emailAddress”;
property name=“address” type=“any” displayname=“address” hint=“This is the Customers address”;
public function init(pAddressObject)
displayname=“init” description=“init” output=“false”
{
setAddress(pAddressObject);
return this;
}
}
Address.cfc
/**
Address
@accessors true
*/
component Address displayname=“Address” hint=“This is the Address Object” output=“false”
{
property name=“ID” type=“numeric” displayname=“Unique ID” hint=“This is the Address Unique ID”;
property name=“Address1” type=“string” displayname=“Address1” hint=“This is the Address1”;
property name=“Address2” type=“string” displayname=“Address2” hint=“This is the Address2”;
property name=“City” type=“string” displayname=“City” hint=“This is the City”;
property name=“State” type=“string” displayname=“State” hint=“This is the State”;
property name=“Province” type=“string” displayname=“Province” hint=“This is the Province”;
property name=“Country” type=“string” displayname=“Country” hint=“This is the Country”;
public function init()
displayname=“init” description=“init” output=“false”
{
return this;
}
So this way the address object is inside the customer object and is empty. When you create a new customer there are many ways to do it but here is one.
oAddress = new testObjects.Address();
newCustomer = new testObjects.Customer(oAddress);
newCustomer.setFirstName("Jim");
newCustomer.setLastName("Sample");
newCustomer.setEmailAddress("Jim.Sample@gmail.com");