我有一个games
表和两个表来存储他们的分数,game_scores
和thirdparty_game_scores
具有完全相同的结构,类似于:
-------------------------GAMES-------------------------
slug | title | technology | (other non-relevant fields)
-------------------------------------------------------
----------------------GAME SCORES----------------------
id (PK) | game_slug | user | team | score | timestamp
-------------------------------------------------------
----------------THIRDPARTY GAME SCORES-----------------
id (PK) | game_slug | user | team | score | timestamp
-------------------------------------------------------
他们的模特如:
class GameScores extends BaseGamesModel {
public function initialize() {
parent::initialize();
$this->belongsTo( 'game_slug', 'Games', 'slug' );
$this->skipAttributes(array('creation_time', 'last_modified'));
}
}
我建立了每周排名,游戏分数仅存储在game_scores
:
$ranking = GameScores::sum(
array(
"column" => "score",
"conditions" => $conditions,
"group" => "team",
"order" => "sumatory DESC"
)
);
有没有办法创建一个模型来连接game_scores
和thirdparty_game_scores
的所有数据,以创建相同的排名而不需要额外的努力?
非常感谢你!
答案 0 :(得分:0)
您可以在模型中动态设置源表。见Can I build a Model for two Tables on PhalconPHP?
您应该使用setSource()方法并将条件放在那里,例如:
$source = 'default_table';
if (class_name($this) === 'A') {
$source = 'A_table';
}
return $source;