在大家使用TP的时候,不可避免的会用到字段映射功能,用着老爽了,但是多个表联结的时候问题却出来了,几个表都有某个字段,且存在于映射字段里面。
这里需要几点
1. 需要继承TP本身的类class CommonModel extends Model\RelationModel
2. 写相关方法
public function openMapInThisSql(){ $this->data_map_open = C('READ_DATA_MAP'); C('READ_DATA_MAP', true); return $this; }
3. 重载_after_select方法,将之前的配置还原回去
protected function _after_select(&$resultSet,$options) { if ($this->data_map_open != null) { C('READ_DATA_MAP', $this->data_map_open); } parent::_after_select($resultSet, $options); }
4. 而在使用的时候是这样的
$this->closeMapInThisSql()->field($fields)->where($map).......
到这里整个过程就结束了,终于可以放心的使用了