ColdBox gurus, what approach should I take if I want to define an object (in model directory) that is not persisted to the database, but want to inject a couple entityService elements into it for objects that are persisted? I don’t even know how to ask this question properly yet…and I’m sorry for the long post. Basically…I just need to know if I have the basic architecture down and if not, what new components I need to add/adjust. Thanks so much!
An example scenario is imagine I want to allow the application user to search for customer information, however behind the scenes there are:
- Two separately managed database tables which store the customer information (Imagine one table from a CRM and another from a non-integrated Sales system). Each table has some information we’d like to display in the search results.
- Though the systems are separately managed, most customers have records in both systems and have a unique identifier, loyaltyID, which is the field we’d use to “merge” the results.
If for example, a user searches for loyaltyID ‘1234’, I imagine being able to lookup the information from both tables (might get a single result from both tables, or just one table, or none), merge it together into one generic Customer object (not mapped/persisted to the database) and loop through an array of these generic Customer objects within the View to present the user with the results. Here’s what I had in mind:
CRMCustomer.cfc (mapped to backend CRM table)
`
component persistent=“true” table=“CRMCustomer” {
// Primary Key
property name=“loyaltyID” fieldtype=“id” column=“loyaltyID” generator=“native” setter=“false”;
// Properties
property name=“name” column=“Name” ormtype=“string”;
property name=“phoneNumber” column=“PhoneNumber” ormtype=“string”;
property name=“address” column=“Address” ormtype=“string”;
property name=“gender” column=“Gender” ormtype=“string”;
property name=“accountNumber” column=“AccountNumber” ormtype=“string”;
}
`
SalesCustomer.cfc (mapped to backend Sales table)
`
component persistent=“true” table=“SalesCustomer” {
// Primary Key
property name=“loyaltyID” fieldtype=“id” column=“loyaltyID” generator=“native” setter=“false”;
// Properties
property name=“name” column=“Name” ormtype=“string”;
property name=“PIN” column=“PIN” ormtype=“string”;
property name=“phoneNumber” column=“PhoneNumber” ormtype=“string”;
property name=“lastPurchase” column=“LastPurchase” ormtype=“date”;
}
`
Customer.cfc (not persisted, represents a single customer with properties set from both tables)
`
component output=“false” accessors=“true” {
// DI Injections
property name=“CRMCustomerService” inject=“entityService:CRMCustomer”;
property name=“SalesCustomerService” inject=“entityService:SalesCustomer”;
// Properties
property name=“loyaltyID” type=“int”;
property name=“name” type=“string”; //originated from CRM
property name=“phoneNumber” type=“string”; //originated from CRM
property name=“address” type=“string”; //originated from CRM
property name=“gender” type=“string”; // originated from CRM
property name=“accountNumber” type=“string”; // originated from CRM
property name=“PIN” type=“string”; // originated from Sales
property name=“lastPurchase” type=“date”; // originated from Sales
//User Functions
/Build some functions here to use the Virtual Entity Services above and place the data into the properties where I want it to go/
}
`