Codeigniter datamapper отношения один ко многим

У меня есть две таблицы rostertype и rostertypeposition

введите описание изображения здесь

Я создал две модели

class Roster_type extends DataMapper{

var $table = "rostertype";
var $has_many = array(
'position'  =>  array(
'class' =>  'Roster_typeposition',
'other_field'   => 'roster_position',
'join_self_as'    =>  '',
'join_other_as' =>  'RosterType'
)
);
function __construct($id = NULL){
parent::__construct($id);
}

function getAllRoster(){

return $this->count();
}
}

class Roster_typeposition  extends DataMapper{

var $table = "rostertypepositions";
var $default_order_by = array('PositionIndex'=>'asc');
var $has_one = array(
'roster_position'   => array(
'class' =>  'Roster_type',
'other_field' => 'position',
'join_self_as'    =>  'RosterType',
'join_other_as' =>  ''
)
);
function __construct($id = NULL){
parent::__construct($id);
}

function get_all_positions(){
$u =  $this->get_iterated();
foreach ($u as $ab=>$d){
echo "<pre>";print_r($d->roster_position->get());echo "</pre>";
}
die();
}
}

Но по какой-то причине я получаю эту ошибку

Error Number: 1146

Table 'ad_8cceab3cf7883a5.rostertype_rostertypepositions' doesn't exist

SELECT `rostertype`.*
FROM (`rostertype`)
LEFT OUTER JOIN `rostertype_rostertypepositions` position_rostertype_rostertypepositions ON `rostertype`.`id` = `position_rostertype_rostertypepositions`.`_id`
WHERE `position_rostertype_rostertypepositions`.`RosterType_id` =  2

Filename: /Applications/MAMP/htdocs/IBM_bluemix/Development/Draftbeast-Dev/libraries/Datamapper.php

Line Number: 1344

Я не знаю, как он генерирует эту таблицу position_rostertype_rostertypepositions, Пожалуйста помогите и что я делаю не так.

1

Решение

Решил это, взяв пустые поля в модели

class Roster_typeposition  extends DataMapper{
var $model = 'rostertypepositions';
var $table = "rostertypepositions";
var $default_order_by = array('PositionIndex'=>'asc');
var $has_one = array(
'roster_position'   => array(
'class' =>  'Roster_type',
'other_field' => 'position',
'join_self_as'    =>  'RosterType',
)
);

А также

class Roster_type extends DataMapper{
var $model = 'Roster_type';
var $table = "rostertype";
var $has_many = array(
'position'  =>  array(
'class' =>  'Roster_typeposition',
'other_field'   => 'roster_position',
'join_other_as' =>  'RosterType'
)
);
1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector