【问题标题】:Join query in doctrine symfony在教义 symfony 中加入查询
【发布时间】:2010-03-18 07:41:54
【问题描述】:

我有两张表 userdetails 和 blog question 架构是

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)

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

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

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

请大家帮帮我

提前致谢

【问题讨论】:

    标签: join symfony1 doctrine


    【解决方案1】:

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

    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
    

    您的 yml 中没有任何内容可以告诉您离开加入时它应该链接的内容。我自己构建了这个,它确实有效

    【讨论】:

    • 谢谢,但是当我运行 symfony 学说时:build --all --no-confirmation 它在路径 BlogQuestion->columns->UserDetails 处出现一个名为“Local”的错误架构元素
    • 然后它也显示相同的错误 Invalid schema element named "Local" at path BlogQuestion->columns->UserDetails
    • 等 20 分钟,我将在办公室检查我的代码,尽管我已经将上面的大写“L”和小写“l”删除了。您可能还需要在 UserDetails 中将 id 设置为主键。
    • UserDetails: 连接: 学说 tableName: user_details 列: id: type: integer(8) fixed: false unsigned: false primary: true autoincrement: true autoincrement: true
    • 您好 THOmas,我刚刚构建了我在上面编辑过的新版本,它确实有效。 (现在在我部署之前将其删除:))
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-09
    • 2018-03-15
    相关资源
    最近更新 更多