[英]Relate to another table without using prefixes
So i have a task of creating a mobile version of an existing website but its built with a different framework which i didnt started. 因此,我有一个创建现有网站的移动版本的任务,但是它使用的框架是我没有开始的。
The client wants to use CakePhp on it. 客户端要在其上使用CakePhp。 so im using CakePhp 2.5.7.
所以即时通讯使用CakePhp 2.5.7。 My question is.
我的问题是。 Is there a way to relate another table from an existing table without using prefixes?
有没有办法在不使用前缀的情况下从现有表关联另一个表?
To make it more clear i have this on my controller 为了更清楚我在控制器上有这个
public function index(){
$this->loadModel('Bulletin');
$bulletins = $this->Bulletin->find('all');
}
in my model 在我的模型中
class Bulletin extends AppModel{
var $useTable = 'bulletin';
var $hasMany = array(
'BulletinComment' => array(
'className' => 'BulletinComment',
'foreignKey' => 'bulletinid',
),
);
}
but the bulletincomment
table on the database has no prefix. 但是数据库上的
bulletincomment
表没有前缀。 and showing error on page 并在页面上显示错误
Error: Table bulletincomments for model bulletincomment was not found in datasource default.
I tried creating BulletinComment
model like this 我试过像这样创建
BulletinComment
模型
class BulletinComment extends AppModel{
var $useTable = 'bulletincomment';
}
but to no avail. 但无济于事。 Im still getting error.
我仍然遇到错误。 Is it possible to use any relation without adding prefixes?
是否可以使用任何关系而无需添加前缀?
Assuming prefixes are setup in the database connection ( /app/Config/database.php
) you can override it for one table if you add this to the model: 假设在数据库连接(
/app/Config/database.php
)中设置了前缀,则可以将前缀覆盖到一个表中(如果将其添加到模型中):
public $tablePrefix = '';
Or you could remove the prefix in the connection and add it back for the models that need it, depending on which is faster. 或者,您可以删除连接中的前缀,然后将其添加回需要它的模型中,具体取决于哪个更快。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.