gpt4 book ai didi

php - Codeigniter datamapper 一对多关系

转载 作者:行者123 更新时间:2023-11-28 23:37:53 25 4
gpt4 key购买 nike

我有两个表 rostertype 和 rostertypepositions

enter image description here

我创建了两个模型

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 的。请帮忙,我做错了什么。

最佳答案

通过在模型中取空字段解决了这个问题

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'
)
);

关于php - Codeigniter datamapper 一对多关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35233277/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com