gpt4 book ai didi

mysql - 我可以在 PhalconPHP 上为两个表构建模型吗?

转载 作者:行者123 更新时间:2023-11-30 22:59:13 24 4
gpt4 key购买 nike

我有一个 games 表和两个表来存储他们的分数,game_scoresthirdparty_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_scoresthirdparty_game_scores 的所有数据串联起来,无需任何额外努力即可创建相同的排名?

非常感谢!

最佳答案

您可以在模型中动态设置源表。参见 Can I build a Model for two Tables on PhalconPHP?

您应该使用 setSource() 方法并将您的条件放在那里,例如:

   $source = 'default_table';
if (class_name($this) === 'A') {
$source = 'A_table';
}
return $source;

关于mysql - 我可以在 PhalconPHP 上为两个表构建模型吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24806202/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com