让我们说我有一张桌子,里面有关于节日的信息.
每个节日都有开始和结束日期.
我想选择在给定日期生活(发生)的所有节日.
这意味着,我想选择他们的开始日期在给定日期之前或之后的所有节日,以及他们的结束日期是在同一日期之后或之后.
所以我继续了节日实体的存储库类,并创建了一个方法来做到这一点.
但是标准参数"findBy"期望的是一个数组,所有的例子都只将其视为一个简单的标准(例如"array('name'=>'billy')"将选择所有具有billy值的行. name column),它只使用比较运算符.
我怎样才能使用其他运算符
>, <, !=, IN, NOT IN, LIKE
Run Code Online (Sandbox Code Playgroud)
等等. ?
谢谢
我需要用QueryBuilder这样的方法构造DQL
[QUERY]... AND WHERE e.type = x OR e.type = Y OR e.type = N [...]
Run Code Online (Sandbox Code Playgroud)
我有数组类型如何将此数组传递给我的查询生成器?
$qb->andWhere($qb->expr()->orx(CONDITIONS));
Run Code Online (Sandbox Code Playgroud)
类型列表将是动态的,调用$qb->andWhere每个foreach类型循环只会使更多AND WHERE不再是OR.
我可以存储乘法orx表达式然后将其添加到andWhere?任何想法如何解决这个,可能是常见的问题?
我试图使用doctrine2执行查询,并需要它返回一个集合对象.
简化代码段:
$players = $this->getEntityManager()
->createQueryBuilder()
->select('p')
->from('...\Player', 'p')
->getQuery()
->getResult();
Run Code Online (Sandbox Code Playgroud)
返回的对象是Player的数组.
有关查询结果格式的信息说:
结果是对象的简单集合(纯)或对象嵌套在结果行(混合)中的数组.
结果类型取决于什么以及如何获得集合对象?
对于Symfony2项目,我必须在博客文章和所谓的平台之间建立关系.平台根据您用于查看站点的域定义特定过滤器.例如:如果您通过url first-example.com加入该网站,该网站将仅提供与此特定平台相关联的博客帖子.
为此,我创建了两个实体Post和Platform.之后我将它们与多对多关系映射在一起.我正试图通过findBy()Doctrines中内置函数的多对多关系来检索数据EntityRepository.
// every one of these methods will throw the same error
$posts = $postRepo->findBy(array('platforms' => array($platform)));
$posts = $postRepo->findByPlatforms($platform);
$posts = $postRepo->findByPlatforms(array($platform));
Run Code Online (Sandbox Code Playgroud)
实体和现有对象$postRepo的正确存储库在哪里.
无论哪种方式:我最终得到以下错误:Post$platformPlatform
ErrorException: Notice: Undefined index: joinColumns in [...]/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php line 1495
[...]/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php:1495
[...]/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php:1452
[...]/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php:1525
[...]/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php:1018
[...]/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php:842
[...]/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php:157
[...]/src/Foobar/BlogBundle/Tests/ORM/PostTest.php:102
Run Code Online (Sandbox Code Playgroud)
是否有可能以这种方式以多对多关系检索相关的entites,或者我被迫自己编写这些函数?奇怪的是:Doctrine不会抛出任何错误:"这不可能.",但是内部E_NOTICE.这就是为什么我认为它应该是可能的,但我在这里错过了一些观点.
剥离到有趣的部分,这两个实体看起来像这样.
<?php
namespace Foobar\CommunityBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
// [...] other namespace stuff
/**
* @ORM\Entity(repositoryClass="Foobar\CommunityBundle\Entity\Repository\PlatformRepository")
* @ORM\Table(name="platforms")
*/
class Platform
{
/** …Run Code Online (Sandbox Code Playgroud) 我有一个具有此属性的实体"容器"
/**
* @ORM\OneToMany(targetEntity="BizTV\ContentManagementBundle\Entity\Content", mappedBy="container")
*/
private $content;
Run Code Online (Sandbox Code Playgroud)
该属性是一个数组集合......
public function __construct() {
$this->content = new \Doctrine\Common\Collections\ArrayCollection();
}
Run Code Online (Sandbox Code Playgroud)
......用这两种标准方法
/**
* Add content
*
* @param BizTV\ContentManagementBundle\Entity\Content $content
*/
public function addContent(\BizTV\ContentManagementBundle\Entity\Content $content)
{
$this->content[] = $content;
}
/**
* Get content
*
* @return Doctrine\Common\Collections\Collection
*/
public function getContent()
{
return $this->content;
}
Run Code Online (Sandbox Code Playgroud)
现在我的问题是,是否有一种平滑的方法可以在getContent()调用中构建一个排序功能?我不是php wiz,当然也没有在symfony2中经验丰富,但我随便学习.
内容实体本身有一个像这样的排序INT,我想对它进行排序:
/**
* @var integer $sortOrder
*
* @ORM\Column(name="sort_order", type="integer")
*/
private $sortOrder;
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用doctrine查询构建器构建一个查询,该构建器连接一个非相关的表,如下所示:
$query = $this->createQueryBuilder('gpr')
->select('gpr, p')
->innerJoin('TPost', 'p')
->where('gpr.contentId = p.contentId')
Run Code Online (Sandbox Code Playgroud)
但这不起作用.我仍然收到一个错误:
错误:标识变量TPost在连接路径表达式中使用但之前未定义.
我搜索了这个错误消息,每个人都回答使用表别名+属性,如p.someAttribute.但是我要加入的表格在表格中没有关系,我开始从中选择.
作为一个普通的mysql查询,我会这样写:
SELECT * FROM t_group_publication_rel gpr
INNER JOIN t_post p
WHERE gpr.content_id = p.content_id
Run Code Online (Sandbox Code Playgroud)
我有什么想法吗?
我有一个DateTime领域:
/**
* Date time posted
* @Column(type="datetime")
*/
private $dtPosted;
Run Code Online (Sandbox Code Playgroud)
通过使用LifeCycleCallback将其设置为默认值
/**
* @PrePersist
*/
function onPrePersist() {
// set default date
$this->dtPosted = date('Y-m-d H:m:s');
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
致命错误:在第46行的D:\ ResourceLibrary\Frameworks\Doctrine\lib\Doctrine\DBAL\Types\DateTimeType.php中的非对象上调用成员函数format()
我试图重现这个查询:
SELECT * FROM `request_lines`
where request_id not in(
select requestLine_id from `asset_request_lines` where asset_id = 1
)
Run Code Online (Sandbox Code Playgroud)
在doctrine查询构建器中,我被困在where_id不在的位置(选择
我目前有:
$linked = $em->createQueryBuilder()
->select('rl')
->from('MineMyBundle:MineRequestLine', 'rl')
->where()
->getQuery()
->getResult();
Run Code Online (Sandbox Code Playgroud) 我需要检查持久化实体是否已更改并需要在数据库上更新.我所做的(并没有奏效)如下:
$product = $entityManager->getRepository('Product')->find(3);
$product->setName('A different name');
var_export($entityManager->getUnitOfWork()->isScheduledForUpdate($product));
Run Code Online (Sandbox Code Playgroud)
该代码始终打印false,我也在检查工作单元之前尝试刷新,但没有工作.
有人有建议吗?