- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
试图将我的 sql 查询转换为 dql,似乎我做错了什么。
我需要基本的连接,像这样。
SELECT a.id, a.title, u.name FROM articles JOIN users ON a.author_id = u.id
SELECT a.id, a.title, u.name FROM Article a JOIN User u WITH a.author_id = u.id
[Semantical Error] line 0, col 34 near 'Article a JOIN': Error: Class 'Article' is not defined.
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="articles")
*/
class Article
{
/**
* @var integer $id
*
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string")
*/
protected $title;
/**
* @ORM\Column(type="integer", name="author_id")
*/
protected $authorId;
/**
* @ORM\Column(type="datetime", name="creation_date")
*/
protected $creationDate;
/**
* @ORM\Column(type="string", name="short_content")
*/
protected $shortContent;
/**
* @ORM\Column(type="string")
*/
protected $content;
public function getId()
{
return $this->id;
}
public function getTitle()
{
return $this->title;
}
public function getAuthorId()
{
return $this->authorId;
}
public function getCreationDate()
{
return $this->creationDate;
}
public function getShortContent()
{
return $this->shortContent;
}
public function getContent()
{
return $this->content;
}
}
<?php
namespace AppBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="fos_user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="bigint")
*/
protected $phone;
/**
* @ORM\Column(type="string")
*/
protected $gender;
/**
* @ORM\Column(type="string")
*/
protected $about;
public function getPhone()
{
return $this->phone;
}
public function getGender()
{
return $this->gender;
}
public function getAbout()
{
return $this->about;
}
}
最佳答案
通过 namespace 引用 DQL 中的实体,即 AppBundle:Article
和 AppBundle:User
,这应该会使错误消失。
使用 association mapping ( old docs ) 而不是 authorId
在您的实体中,这样 Doctrine 将负责加载作者:
/**
* @ORM\ManyToOne(targetEntity="User")
* @ORM\JoinColumn(name="author_id", referencedColumnName="id")
**/
private $author;
public function getAuthor() {
return $this->author;
}
public function setAuthor($author) {
$this->author = $author;
}
SELECT a FROM AppBundle:Article a ORDER BY a.creationDate DESC
...
$author = $article->getAuthor();
关于symfony - dql 查询错误类未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32570983/
如何形成 DQL 查询以获取不包括文档 um 中创建的虚拟文档(同时添加对文件的引用)的文件列表。任何人都可以帮助我。 最佳答案 如 r_link_count is > 0 并且 object 是一个
所以,我有这个实体结构: User有一些Email s(同时多个); 每个Email属于Domain s (如果 email@example.com,那么我的数据库中有 Domain “example
我在 documentum 中发现了未记录的 DQL 命令(在 D6.5 上测试过) 执行计数 session 此查询输出中的“hot_list_size”、“warm_list_size”、“col
我们总是可以通过语法(select * from table_name)从表中找到相应的表属性,有没有办法反之亦然我的意思是有没有办法用属性名找到表名? 最佳答案 好吧,如果你所说的表是指对象,你可以
谁能告诉我如何仅使用“DQL”将文档从客户端机器导入到 documentum 存储库,下面是我正在使用的命令...... 我得到的错误是 [DM_SYSOBJECT_E_CANT_ACCESS_FIL
是否有机会从所有参数代替标记的学说查询生成器对象中获取 DQL 查询? 类(class) $query->getDQL()将返回查询但使用参数标记而不是实际值,即使它们已由 setParameter
试图将我的 sql 查询转换为 dql,似乎我做错了什么。 我需要基本的连接,像这样。 SELECT a.id, a.title, u.name FROM articles JOIN users ON
我使用一对一的关系作为实体的 id: Actor 实体 $metadata->mapOneToOne([ 'fieldName' => 'user', 'id' => true,
通常,如果我运行如下所示的 DQL 查询,它将返回实体对象列表: $d = $this->getDoctrine()->getRepository('xxxWebsiteBundle:Location
有人可以建议我使用 DQL 查询来查找 documentum 中存储库中的事件用户数吗? 下面是我正在使用的查询,但它没有给出正确的结果,有人可以提出建议吗? select count(user_na
如果我们提供相应文件的 object_id,任何人都可以使用 Documentum 查询语言提供解决方案,以访问从 documentum checkout 的文件的文件夹详细信息。谢谢………… 最佳答
如何从日期时间格式 (00-00-0000 00:00:00) 中提取不同的年份?我正在使用 Symfony 2 和 DQL。 在 SQL 中,它将是: SELECT DISTINCT extract
我有这个存储库功能来选择特定日期内与图像拟合相关的所有投票: public function getTopNImages(int $n) { $date = date_form
在我的实体“Item”中,有一个称为“products”(实体“Product”)的 ArrayCollection 属性,该属性可以为空 我需要在一次 DQL 调用中对“Item”实体数组进行所有产
我正在尝试从表 o 中 SLECT * ,其中供应商是我传递的内容。(这是在 Doctrine 存储库的上下文中)。然后我想运行一个子查询和 SELECT * FROM AppBundle:Price
我正在尝试更新一个查询中某些表中的一行。我已经完成了: $this->getDoctrine()->getManager() ->createQuery('
我将 Symfony 2 与 Doctrine 一起使用,并且我有两个实体加入了多对多关联。假设我有两个实体:User 和 Group,db 上的相关表是 users、groups 和 users_g
我正在尝试将这个我认为简单的 mysql 查询转换为 Doctrine dql,但是,我现在遇到了很大的困难...... SELECT (c.prix-aggregates.AVG) AS test
我在 MySQL 数据库中有 2 个表,我使用的是 doctrine 1.2 和 symfony 1.4.4 装机量和备用量 Installedbase: ib_id app_id location
我正在 Doctrine Documentation 中尝试这部分其中你可以: 手动编写DQL 对于您这些 SQL 爱好者,我们没有忘记您。您可以选择手动编写 DQL 查询并将它们解析为 Doctri
我是一名优秀的程序员,十分优秀!