php - Codeigniter datamapper one to many relationship -
i have 2 table rostertype , rostertypepositions
i have created 2 model
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 $ab=>$d){ echo "<pre>";print_r($d->roster_position->get());echo "</pre>"; } die(); } }
but reason getting error
error number: 1146 table 'ad_8cceab3cf7883a5.rostertype_rostertypepositions' doesn't exist select `rostertype`.* (`rostertype`) left outer join `rostertype_rostertypepositions` position_rostertype_rostertypepositions on `rostertype`.`id` = `position_rostertype_rostertypepositions`.`_id` `position_rostertype_rostertypepositions`.`rostertype_id` = 2 filename: /applications/mamp/htdocs/ibm_bluemix/development/draftbeast-dev/libraries/datamapper.php line number: 1344
i dont know how generating table position_rostertype_rostertypepositions
. please , doing wrong.
solved taking empty fields in model
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', ) );
and
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' ) );
Comments
Post a Comment