Hello Forum, Im new to the DataMapper ORM!
I would like to get some help setting up the DataMapper to 3 object/tables from TankAuth.
Or rather, i would love to get some explaining on how the works of DataMapper considering the correct thinking when setting up DataMapper against non standard DataMapper tables.
Ok so i got these three objects.. User, User_profile & Role.
In DB they have these fields as described below:
Users
—————-
id
username
password
email
role_id (holds the role id of user)
...
Roles
—————-
id
role
default
user_profiles
———————
id
user_id (holds the id of the user the specific profile refering to)
country
website
I know that this isn“t standard DataMapper, what should u call it, definition, but its okey.
Now I would like to link these objects together with the help of DataMapper Advanced Relationships. (http://datamapper.wanwizard.eu/pages/advancedrelations.html)
This is my code so far, ive tried to fiddling around with the relationships for a few hours without any success…. as said im new to ORM and DataMapper..
class User_dm extends DataMapper {
var $has_one = array(
'role' => array(
'class' => 'Role_dm',
'join_self_as' => 'role_id'
),
'user_profile'
);
var $table = 'users';
public function __construct($id = NULL)
{
parent::__construct($id);
}
}
class Role_dm extends DataMapper {
var $has_many = array(
'user' => array(
'class' => 'User_dm',
'join_self_as' => 'id',
'join_other_as' => 'role_id'
)
);
var $table = 'roles';
public function __construct($id = NULL)
{
parent::__construct($id);
}
}
class User_profile extends DataMapper {
var $has_one = array(
'user'
);
public function __construct($id = NULL)
{
parent::__construct($id);
}
}
Anybody that can help me out? would be much appreciated! or give me some explanation on the join criteras and how i should use them!