我试图在 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/