[eluser]OverZealous[/eluser]
I understand now. You want to include the columns from the Users table along side columns from the Person table when querying Users, in an automatic fashion, correct? Your User table would have, for example, a person_id column that represents which person that user is connected to?
You can create queries like that in DMZ pretty closely, just not 100% automatically (I'll get to that in a second...).
Here's the setup:
Tables
Code:
// people Columns
id, firstname, lastname, phone, email
class Person extends DataMapper {
var $table = 'people';
var $has_one = array('user');
var $validation = ...
}
class User extends DataMapper {
var $has_one = array('person');
var $validation = ...
}
Controller
Code:
$u = new User();
// Include all of the related person columns (except ID, since it won't get overridden) in the results
// By passing FALSE for the 3rd arg, no prefix will be added
$u->include_related('person', '*', FALSE)->get_by_id($user_id);
echo($u->firstname . ' ' . $u->lastname);
To automate this, set up the user like so:
Code:
class User extends DataMapper {
function get($limit = '', $offset = '')
{
// optionally, offer an override
$this->include_related('person', '*', FALSE);
parent::get($limit, $offset);
}
}
You can even use the arrayutils extension to save information in just a few extra lines:
Now, I understand this is only 1/2 of the problem (and the easy half at that). But I have an idea for a later version of DMZ (too late for 1.4.0). What if, instead of using class inheritance, I added a class variable called (for example), $inherit_from. This would accept a string value for the parent class.
Then (and this is the ugly part), DMZ could automate connecting the CRUD operations to the parent class. It would require a lot of work and testing, though. I'll put it on the "think about it" list.
(Of course, the easy solution is to just throw it all into the same table. Then you don't have to do all this rigmarole to glue two tables together.)
And I don't recommend forking it yourself unless you can give a lot of time to it. I've spent well over 20 hours updating documentation at this point, and probably several hundred hours in the updates, example app, and testing I've provided.