mysql - 插入 1.6 大于/小于

标签 mysql propel

我试图在 Propel ORM 中做一些非常简单的事情,但我似乎无法解决或找不到答案。

基本上我有一个名为 post 的表和一个名为 post_history 的表。每次有人对帖子进行编辑时,以前的版本首先保存到 post_history。

我对每个帖子都有一个“撤消”按钮,我只想为帖子选择最后一个“post_history”记录并从历史记录中恢复帖子数据。要选择比我的帖子更早的最后一个历史记录,我该如何选择 GREATER 或 LESS than in propel?

如果我这样做:

$postHistory = PostHistoryQuery::create()
                ->filterByPostId($post->getId())
                ->filterByCreated(array("max" => $post->getUpdated()))
                ->orderById("DESC")
                ->limit(1);

指定“max”的 filterByCreated 确实选择了最后一个“post_history”,但如果您再次单击撤消,它会选择相同的记录,因为 max 似乎指定小于或等于而不是小于。它可能需要自定义查询?我想我错过了一个我也找不到答案的技巧。到目前为止,我对答案的搜索没有帮助。

非常感谢任何帮助。

最佳答案

好的,所以我在 SO 上发布了一个问题寻求帮助,并在 30 分钟内通过尝试解决了这个问题。典型的,嗯?它可能对其他人有用,所以这就是我所做的:

$postHistory = PostHistoryQuery::create()
                ->filterByPostId($post->getId())
                ->filterByCreated(array("max" => $post->getUpdated()))
                ->orderById("DESC")
                ->limit(1);

更改为:

$postHistory = PostHistoryQuery::create()
                ->filterByPostId($post->getId())
                ->where('post_history.created < ?', $post->getUpdated())
                ->orderById("DESC")
                ->limit(1);

->where() 子句允许您指定许多选项,例如 >、<、LIKE 等...

关于mysql - 插入 1.6 大于/小于,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25864294/

相关文章:

python - 客户端不支持服务器请求的认证协议(protocol)考虑升级mysql客户端

php - Propel 是否知道对象何时被软删除,以便子实体仍然可以显示其已删除的父实体?

javascript - sfPropelPager 只生成 5 页

php - 无法插入表中

php - 使用 from list 和 left join 之间的区别

MySQL 更新联合选择

php - 使用 Propel ORM 保存和检索 blob

php - 不在数据库中的表上的外键,使用 ORM

php - Propel - 使用多个外键连接同一个表

mysql - 如何使用 R 将列表放入数据库