1
我需要重构项目,我有问题。以下是旧的工作模式,其中“活跃”列在“人员”表中。我需要将“活动”列移动到“people_translations”表中。 你有任何想法来修改scopeActive方法吗? 非常感谢!Laravel - 模型修改
旧的工作模式:
class BaseModel extends Eloquent
{
public function scopeActive($query)
{
return $query->where($this->table . '.active', '=', 1);
}
}
class People extends BaseModel
{
protected $table = 'peoples';
protected $translationModel = 'PeopleTranslation';
}
class PeopleTranslation extends Eloquent
{
public $timestamps = false;
protected $table = 'peoples_translations';
}
旧表结构:
Table: peoples
id | type | date | active
-------------------------
7 | .... | ... | 1
Table: peoples_translations
id | people_id | language_id | name
-----------------------------------
1 | 7 | 1 | Ann
旧的查询:
$人民= \人::激活() - >获得();
新表结构:
Table: peoples
id | type | date
----------------
7 | .... | ...
表:peoples_translations
id | people_id | language_id | name | active
--------------------------------------------
1 | 7 | 1 | Ann | 1
我不明白你为什么需要额外的表格。 “人民”和“人民通讯”是什么关系? hasOne?有很多? – Tim
Tim,很多语言都有很多language_id,所以有很多 – Paul