Doctrine 1
  1. Doctrine 1
  2. DC-661

Subquery Doctrine Couldn't find class

    Details

    • Type: Bug Bug
    • Status: Reopened
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2.2
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      I'm trying to create a query like this one :

      SELECT nombre, (select count( * ) from alojamiento a left join localidad l on a.localidad_id=l.id where p.id=l.provincia_id and a.activo=true) as total from provincia p

      $q = Doctrine_Query::create()
      ->select('p.nombre')
      ->addSelect('(select count( * ) from alojamiento a left join
      localidad l on a.localidad_id=l.id where p.id=l.provincia_id and
      a.activo=true)')
      ->from('provincia p');

      but it fails : error 500, couldn't find class a.

      And :
      $q = Doctrine_Query::create() ->select('nombre') ->addSelect('(select count( * ) from alojamiento left join localidad on
      alojamiento.localidad_id=localidad.id where
      provincia.id=localidad.provincia_id and alojamiento.activo=true)') ->from('provincia');

      leads to : SQLSTATE[42S22]: Column not found: 1054 Unknown column 'a.localidad_id' in 'on clause'.

        Activity

        Hide
        Jonathan H. Wage added a comment -

        You are using table names in your query and not model names.

        For future reference, the Jira is for reporting bugs/issues. You can ask user questions on the Doctrine mailing lists: http://www.doctrine-project.org/community

        Show
        Jonathan H. Wage added a comment - You are using table names in your query and not model names. For future reference, the Jira is for reporting bugs/issues. You can ask user questions on the Doctrine mailing lists: http://www.doctrine-project.org/community
        Hide
        Mauro E. added a comment - - edited

        My model names are: alojamiento, localidad and provincia I don't use table names.

        Show
        Mauro E. added a comment - - edited My model names are: alojamiento, localidad and provincia I don't use table names.
        Hide
        Jonathan H. Wage added a comment -

        Can you provide a test case because I am not able to reproduce any problems. All of our subquery tests are passing currently and I can't seem to find any problems like you describe.

        Show
        Jonathan H. Wage added a comment - Can you provide a test case because I am not able to reproduce any problems. All of our subquery tests are passing currently and I can't seem to find any problems like you describe.
        Hide
        Mauro E. added a comment - - edited

        Hope it is not my stupid fault, I apologize if it's my fault.

        My schema.yml is:

        Alojamiento:
        actAs:
        Timestampable:
        Sluggable:
        unique: true
        fields: [nombre]
        canUpdate: true
        SoftDelete:
        columns:
        id:
        type: integer(4)
        primary: true
        unique: true
        notnull: true
        autoincrement: true
        localidad_id:
        type: integer(4)
        notnull: true
        nombre:
        type: string(255)
        notnull: true
        activo:
        type: boolean
        notnull: true
        default: false
        relations:
        Localidad:
        foreignType: one

        Localidad:
        actAs:
        Sluggable:
        unique: true
        fields: [nombre]
        canUpdate: true
        columns:
        id:
        type: integer(4)
        primary: true
        unique: true
        notnull: true
        autoincrement: true
        nombre:
        type: string(250)
        unique: true
        notnull: true
        provincia_id:
        type: integer(4)
        notnull: true
        relations:
        Provincia:
        onDelete: CASCADE
        local: provincia_id
        foreign: id

        Provincia:
        actAs:
        Sluggable:
        unique: true
        fields: [nombre]
        canUpdate: true
        columns:
        id:
        type: integer(4)
        primary: true
        unique: true
        notnull: true
        autoincrement: true
        nombre:
        type: string(250)
        unique: true
        notnull: true
        relations:
        Localidades:
        type: many
        class: Localidad
        local: id
        foreign: provincia_id
        orderBy: nombre

        Show
        Mauro E. added a comment - - edited Hope it is not my stupid fault, I apologize if it's my fault. My schema.yml is: Alojamiento: actAs: Timestampable: Sluggable: unique: true fields: [nombre] canUpdate: true SoftDelete: columns: id: type: integer(4) primary: true unique: true notnull: true autoincrement: true localidad_id: type: integer(4) notnull: true nombre: type: string(255) notnull: true activo: type: boolean notnull: true default: false relations: Localidad: foreignType: one Localidad: actAs: Sluggable: unique: true fields: [nombre] canUpdate: true columns: id: type: integer(4) primary: true unique: true notnull: true autoincrement: true nombre: type: string(250) unique: true notnull: true provincia_id: type: integer(4) notnull: true relations: Provincia: onDelete: CASCADE local: provincia_id foreign: id Provincia: actAs: Sluggable: unique: true fields: [nombre] canUpdate: true columns: id: type: integer(4) primary: true unique: true notnull: true autoincrement: true nombre: type: string(250) unique: true notnull: true relations: Localidades: type: many class: Localidad local: id foreign: provincia_id orderBy: nombre
        Hide
        Jonathan H. Wage added a comment -
        Show
        Jonathan H. Wage added a comment - You can read about how to create unit tests here http://www.doctrine-project.org/projects/orm/1.2/docs/manual/unit-testing/en#unit-testing

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Mauro E.
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: