Profesional
和Plan
之间存在多对多的关系,所以我写了以下代码:
Profesional.php
class Profesional extends BaseModel {
static $table_name = 'profesionales';
static $primary_key = 'idprofesional';
static $has_many = array(
array(
'_planes',
'class_name' => 'Plan',
'through' => '_profplanes'
),
array(
'_profplanes',
'class_name' => 'ProfPlan',
'foreign_key' => 'profesional'
)
);
}
profplan.php
class ProfPlan extends BaseModel{
static $table_name = 'profplanes';
static $belongs_to = array(
array(
'_plan',
'class_name' => 'Plan',
'foreign_key' => 'plan'
),
array(
'_profesional',
'class_name' => 'Profesional',
'foreign_key' => 'profesional'
)
);
}
plan.php
class Plan extends BaseModel {
static $table_name = 'planes';
static $primary_key = 'idplan';
static $has_many = array(
array(
'_profplanes',
'class_name' => 'ProfPlan',
'foreign_key' => 'plan'
)
);
}
但我得Class Profplane does not exist
。错误在哪里?我做错了什么?
答案 0 :(得分:0)
修复课程/表格拼写!它很容易在你的代码中尽早修复,并在以后成为维护噩梦= P! “Plan-> Plans''Profesional => Professional',”Professionales->“Professionals”。
老实说,phpactiverecord中的直通关系代码很烦人,变化无常,而且一般都需要仔细查看。
你应该展示你实际上是如何调用代码的,但我会假设你正在做
Professional::find(1)
$professional->_plans, //Error is thrown here
您需要设置代码,以便定义ProfPlan->_plans
(或您的_planes
),而不仅仅是ProfPlan->_plan
。 Phpactiverecord需要明确地知道它将要经历的关系。如果您需要更清楚的解释,请告诉我。