ORM: nested objects without foreign keys
I'm trying to use ORM to CRUD some change logs. I already have a pretty simple table structure that would require 2 joins. I've created entities for both of the joined objects. I'd like to fetch change logs with these objects populated.
I already have the tables. I don't have or want any official foreign keys setup; I just use the "_fk" convention to indicate it references the PK of another table.
change_logs
---------------
change_log_id
change_log_type_id_fk
message
user_id_fk
change_log_types
----------
change_log_type_id
name
users
----------
user_id
name
------------------
component entityname="ChangeLog" accessors="true" persistent="true" table="change_logs" {
property name="id" type="numeric" column="change_log_id" fieldtype="id" generator="native";
property name="message" type="string";
property name="type" column="change_log_type_id_fk" cfc="ChangeLogType";
property name="user" column="user_id_fk" cfc="User";
}
component entityname="ChangeLogType" accessors="true" persistent="true" table="change_log_types" {
property name="id" type="numeric" column="change_log_type_id" fieldtype="id" generator="native";
property name="name" type="string";
}
component entityname="User" accessors="true" persistent="true" table="users" {
property name="id" type="numeric" column="user_id" fieldtype="id" generator="native";
property name="name" type="string";
}
At best, the "user" property comes back as an int -- the user id; at worst the whole thing blows up failing on some DDL issue or trying to create a foreign key or not understanding the type. What I want is the user and type properties to be their User.cfc and ChangeLogType.cfc entity object equivalents.
This shouldn't be that hard. How can I do this? I've tried many things (including messing with hdmxml files) with no luck. Any help would be greatly appreciated. Thank you!
