[eluser]mak.gnu[/eluser]
hi,
This is my first application in ORM and I'm using Datamapper DMZ for this. Please Excuse me if this is very basic Question but I'm litile confused
my app is a classified for a trucks. Here is a mine database structure.
Code:
classifieds
---id
---truck_id
---user_id
---description
users
---id
---email
trucks
---id
---name
---model
classifieds_trucks
---id
---truck_id
---classified_id
classifieds_users
---id
---user_id
---classified_id
categories
---id
---name
categories_trucks
---id
---truck_id
---category_id
Models used
class Classified extends DataMapper{
var $has_one = array(
'truck'=>array(),
'user'=>array(),
'category'=>array()
);
}
class User extends DataMapper {
var $has_one = array('group');
var $has_many = array(
'created_classified' => array(
'class' => 'classified',
'other_field' => 'creator'
),
'edited_classified' => array(
'class' => 'classified',
'other_field' => 'editor'
),
// bugs assigned to this user
'classified'
);
}
class Truck extends DataMapper{
var $has_one = array('category');
}
class Category extends DataMapper{
var $has_many = array('truck'=>array() );
}
On this Structure I's saving classifieds as follows along with classified an user is also being saved only with his email and phone_no
Code:
function save(){
$clasi = new Classified();
foreach ($_POST as $k => $val) {
$clasi->$k = $this->input->post($k);
}
$u = new User();
$u->phone_no = $this->input->post('phone_no');
$u->email = $this->input->post('email');
$u->save();
if (!$u->save()) {
foreach ($u->error->all as $error) {
echo $error;
}
}
$u->clear();
// To save into classified and its relation with users
$u = new User();
$u->where('email',$this->input->post('email'))->get();
$t = new Truck();
$t->where('id',$this->input->post('truck_id'))->get();
if (!$clasi->save(array($u,$t))) {
foreach ($clasi->error->all as $error) {
echo $error;
}
}
}
after running this function classified and user is being saved but not the joining tables.
an help would be appreciated