在doctrine symfony加入查询 [英] Join query in doctrine symfony

查看:137
本文介绍了在doctrine symfony加入查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表用户名和博客问题模式是

  UserDetails:
connection:doctrine
tableName:user_details
列:
id:
类型:整数(8)
固定:假
名称:
类型:字符串(255)
fixed:false

BlogQuestion:
连接:doctrine
tableName:blog_question
列:
question_id:
类型:integer 8)
fixed:false
unsigned:false
primary:true
autoincrement:true
blog_id:
类型:整数(8)
固定:false
user_id:
类型:整数(8)
fixed:false
question_title:
类型:string(255)

我使用一个检索所有的问题和用户的详细信息,从这个两个表我的联接查询联接查询是



'pre> $ q = Doctrine_Query ::创建()
- >选择('* )
- >从( BlogQuestion U)
- > leftJoin( u.UserDetails P);
$ q-> execute();

但它显示此错误未知关系别名UserDetails



任何人帮助我



提前感谢

解决方案

为什么你没有在你的教义中建立关系?

  UserDetails:
connection:doctrine
tableName:user_details
列:
id:
类型:整数(8)
固定:假
无符号:假
主要:真
autoincrement:true

BlogQuestion:
连接:doctrine
tableName:blog_question
列:
question_id:
类型:整数(8)
fixed:false
unsigned:false
primary:true
autoincrement:true
blog_id:
类型:integer(8)
fixed:false
USER_ID:
类型:整数(8)
固定:假
QUESTION_TITLE:
类型:字符串(255)
关系:
UserDetails:
local:user_id

你的yml告诉教义当你离开加入时应该链接什么。我刚刚建立自己,它的工作


I have two tables userdetails and blog question The schema is

UserDetails:
  connection: doctrine
  tableName: user_details
  columns:
    id:
      type: integer(8)
      fixed: false
    name:
      type: string(255)
      fixed: false

BlogQuestion:
  connection: doctrine
  tableName: blog_question
  columns:
    question_id:
      type: integer(8)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
    blog_id:
      type: integer(8)
      fixed: false
    user_id:
      type: integer(8)
      fixed: false
    question_title:
      type: string(255)

I am using one join query for retrieving all the questions and user details from this two tables My join query is

$q = Doctrine_Query::create()
    ->select('*')
    ->from('BlogQuestion u')
    ->leftJoin('u.UserDetails p');
    $q->execute();

But it is showing this error Unknown relation alias UserDetails

Pls anybody help me

Thanks in advance

解决方案

why have you not set up a relationship in your doctrine?

UserDetails:
  connection: doctrine
  tableName: user_details
  columns:
    id:
      type: integer(8)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true

BlogQuestion:
  connection: doctrine
  tableName: blog_question
  columns:
    question_id:
      type: integer(8)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
    blog_id:
      type: integer(8)
      fixed: false
    user_id:
      type: integer(8)
      fixed: false
    question_title:
      type: string(255)
  relations:
    UserDetails:
      local: user_id

there is nothing in your yml to tell doctrine what it should be linking on when you left join. I have just build this myself and it does work

这篇关于在doctrine symfony加入查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆