我正在研究现有项目.获取这样的记录:
$this->courses = Doctrine_Core::getTable('Course')->findByUserId($this->userId);
Run Code Online (Sandbox Code Playgroud)
现在我想按用户名对上述记录进行排序,但我不知道怎么做?
这段代码有什么解决方案吗?
谢谢
我有一个SQL查询返回一个表(国家)中的所有行,这些表在另一个表(ducks)中有相关条目,但我很难将其转换为DQL.这是一个标准的一对多关系,因为每个国家可以有多个鸭子,我相信它都是正确设置的,因为我可以在一个国家内返回鸭子并使用标准代码返回该国家.
工作查询是:
SELECT c.* FROM country c
INNER JOIN ducks d
ON c.id = d.country_id
GROUP BY c.country
ORDER BY c.country ASC
Run Code Online (Sandbox Code Playgroud)
我试过将其转换为:
SELECT c FROM WfukDuckBundle:Country c
INNER JOIN WfukDuckBundle:Ducks d
ON c.id = d.country_id
GROUP BY c.country
ORDER BY c.country ASC
Run Code Online (Sandbox Code Playgroud)
这会产生以下错误:
[Semantical Error] line 0, col 79 near 'd ON': Error: Identification Variable
WfukDuckBundle:Ducks used in join path expression but was not defined before.
Run Code Online (Sandbox Code Playgroud)
我对Symfony/Doctrine很新,所以我怀疑它可能是显而易见的!
我正在使用带有学说的Symfony 2.0.11
更新:我也尝试过:
SELECT c FROM WfukDuckBundle:Country c
INNER JOIN c.ducks d …Run Code Online (Sandbox Code Playgroud) $qb = $this->createQueryBuilder('t');
return $qb
->join('t.customers', 'c')
->where($qb->expr()->eq('t.user', $user->getId()))
->andWhere($qb->expr()->gt($qb->expr()->count('c'), 0))
->orderBy('t.name')->getQuery()->getResult();
Run Code Online (Sandbox Code Playgroud)
上面的查询(Doctrine2生成一个)给了我这个错误:
#1111 - Invalid use of group function
但奇怪的是我没有使用GROUP BY.非常感谢任何帮助,谢谢.
SELECT t0_.id AS id0,
t0_.slug AS slug1,
t0_.name AS name2,
t0_.description AS description3,
t0_.user_id AS user_id4
FROM tag t0_
INNER JOIN customers_tags c2_ ON t0_.id = c2_.tag_id
INNER JOIN customer c1_ ON c1_.id = c2_.customer_id
WHERE t0_.user_id = 1 AND COUNT(c1_.id) > 0
ORDER BY t0_.name ASC
Run Code Online (Sandbox Code Playgroud) 我刚刚将Zend项目上传到我的CentOS服务器.我正在使用Doctrine ORM,所以这要求我说明我正在使用的命名空间.
我的项目在我的Windows机器上运行正常,但是当我尝试在服务器上运行它时,我得到了
Parse error: syntax error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING or '(' in ************/Bootstrap.php on line 2
Run Code Online (Sandbox Code Playgroud)
错误.第2行是
use Doctrine\ORM\EntityManager,
Doctrine\ORM\Configuration;
Run Code Online (Sandbox Code Playgroud)
我对Linux很新,也许我认为它的Linux有问题我错了,所以如何解决这个错误呢?
谢谢
我想在doctrine中进行这个sql查询:
SELECT *
FROM (
(SELECT *, e1.stop_date as sort_date FROM `event` e1 WHERE ...)
UNION
(SELECT *, e2.start_date as sort_date FROM `event` e2 WHERE ...)
) e3
ORDER BY e3.sort_date
Run Code Online (Sandbox Code Playgroud)
我想将symfony模型的结果连接到事件表,比如使用:
Doctrine_Core::getTable('Event')->createQuery('e')
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
当我尝试执行此DQL查询时:
SELECT r, s FROM Rule r
JOIN r.splash_page s
WHERE r.active = 1
Run Code Online (Sandbox Code Playgroud)
我想要做的只是加入两个实体,我得到这个错误:
Notice: Undefined index: rules in C:\xampp\htdocs\excap\vendor\doctrine\orm\lib\Doctrine\ORM\Internal\Hydration\ObjectHydrator.php on line 110
Notice: Undefined index: rules in C:\xampp\htdocs\excap\vendor\doctrine\orm\lib\Doctrine\ORM\Internal\Hydration\ObjectHydrator.php on line 428
Notice: Undefined index: rules in C:\xampp\htdocs\excap\vendor\doctrine\orm\lib\Doctrine\ORM\Internal\Hydration\ObjectHydrator.php on line 428
Notice: Undefined index: rules in C:\xampp\htdocs\excap\vendor\doctrine\orm\lib\Doctrine\ORM\Internal\Hydration\ObjectHydrator.php on line 428
Notice: Undefined index: rules in C:\xampp\htdocs\excap\vendor\doctrine\orm\lib\Doctrine\ORM\Internal\Hydration\ObjectHydrator.php on line 428
Run Code Online (Sandbox Code Playgroud)
这些是我的Entity文件的一部分,我在其中声明它们之间的关系:
// Rule.php
/**
*
* @var type
* @ManyToOne(targetEntity="SplashPage", inversedBy="rules")
*/
protected $splash_page;
Run Code Online (Sandbox Code Playgroud)
// SplashPage.php
/**
*
* @var …Run Code Online (Sandbox Code Playgroud) 我在这里关注文档:
这些是命令
php app/console doctrine:mapping:convert xml ./src/Acme/BlogBundle/Resources/config/doctrine/metadata/orm --from-database --force
php app/console doctrine:mapping:import AcmeBlogBundle annotation
php app/console doctrine:generate:entities AcmeBlogBundle
Run Code Online (Sandbox Code Playgroud)
我在这里看到新的实体"
Acme/BlogBundle/AcmeBlogBundle/Entity
Run Code Online (Sandbox Code Playgroud)
但我想知道如何将实体添加到它们自己的命名空间中
Acme/BlogBundle/AcmeBlogBundle/Entity/Foo
Acme/BlogBundle/AcmeBlogBundle/Entity/Bar
Run Code Online (Sandbox Code Playgroud)
这样我就可以将Foo和Bar数据库的实体分开.
更新:
或者它应该像这样结构:
Acme/BlogBundle/AcmeBlogBundle/Foo/Entity
Acme/BlogBundle/AcmeBlogBundle/Bar/Entity
Run Code Online (Sandbox Code Playgroud)
思考?
用户有更多任务,1:N连接.
视觉:
admin
task1 2011/01/01 00:00:01
task2 2011/01/01 00:00:04
task3 2011/01/01 00:00:02
user2
task1 2011/03/01 00:01:01
task2 2011/03/01 00:01:04
task3 2011/03/01 00:01:02
Run Code Online (Sandbox Code Playgroud)
(参见上一个问题的架构)
如何离开加入用户和最后的"任务",而不是全部?
问题是我不知道如何用纯SQL做到这一点......我在这里看到了一些例子,但它们没有用.
如何将服务管理器注入Doctrine存储库以允许我检索Doctrine Entity Manager?
我使用ZF2-Commons DoctrineORMModule并且正在尝试实现Doctrine Tutorial(下面链接中的教程底部)中列出的存储库示例:
http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/getting-started.html
但是,我不断收到一条消息" 致命错误:在C:\ zendProject\zf2 ... "中的非对象上调用成员函数get(),这表明我没有服务定位器的工作实例.
我的Doctrine存储库看起来像这样:
namespace Calendar\Repository;
use Doctrine\ORM\EntityRepository,
Calendar\Entity\Appointment,
Calendar\Entity\Diary;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class ApptRepository extends EntityRepository implements ServiceLocatorAwareInterface
{
protected $services;
public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
$this->services = $serviceLocator;
}
public function getServiceLocator()
{
return $this->services;
}
public function getUserApptsByDate()
{
$dql = "SELECT a FROM Appointment a";
$em = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
$query = $em()->createQuery($dql);
return $query->getResult();
}
}
Run Code Online (Sandbox Code Playgroud)
然后,我想使用以下模式在我的控制器中调用它:
$diary = $em->getRepository('Calendar\Entity\Appointment')->getUserApptsByDate();
Run Code Online (Sandbox Code Playgroud)
编辑:附加的链接表明我可能需要将类转换为服务,
/sf/answers/945615961/
但是,如果这是最佳路线,那么我将如何让我的Doctrine Entity了解该服务.目前,我在指向该类的doc块中包含一个注释. …
我正在使用Silex和Doctrine.在我需要bindValue获取LIMIT值之前,它对我来说非常有用.PDO的默认行为是在数字周围插入引号,这显然是不可行的.因此,解决方案是设置data_type参数.不幸的是,它抛出了一个错误.
我的守则
$start_num = 3;
$stmt = $app['db']->prepare('SELECT * FROM myTable LIMIT ?,10');
$stmt->bindValue(1, $start_num, PDO::PARAM_INT);
Run Code Online (Sandbox Code Playgroud)
错误
Fatal error: Class 'Silex\Provider\PDO' not found in ...
Run Code Online (Sandbox Code Playgroud)
我发现的关于这个问题的大多数答案都说这是PDO没有被编译/启用的明显迹象,但是我一直在使用Doctrine(它依赖于PDO?)成功一段时间没有问题.
这是Doctrine的问题吗?我的代码有问题吗?
doctrine ×10
php ×6
mysql ×3
symfony ×3
symfony1 ×3
doctrine-orm ×2
symfony-1.4 ×2
entity ×1
linux ×1
namespaces ×1
pdo ×1
service ×1
silex ×1
sql ×1
sql-order-by ×1
subquery ×1
union ×1