Andreu Ramos
Andreu Ramos

Reputation: 2908

Column not found error in Criteria

I'm working on a symfony project and i need to query a many to many relationship, so i made this criteria based function to query the database:

    //Create Criteria Object
    $c1 = new Criteria();
    //Selecting the rows in the link table that matches the Table1 id (parameter)
    $c1->add(LinktablePeer::TBL1_CODIGO,$parameter,Criteria::EQUAL);
    //Selecting the rows in Table2 that matched with the last query
    $c1->addJoin(LinktablePeer::TBL2_CODIGO,Table2Peer::TBL2_CODIGO);
    $list = LinktablePeer::doSelect($c1);

but it throws me this strange error

[wrapped: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'link_table.ID' in 'field list']

Is strange because i have no column named ID in that table. Why is this happening? How can i fix it?

The question in other words:

Is there an option for the php symfony propel:build-model command that prevents generating the "ID" column for those tables that don't have a primary key? Thank you for your time ;)

Upvotes: 1

Views: 1060

Answers (1)

nibbles
nibbles

Reputation: 11

I've found that the problem was the dump command task was trying to export a view in my mysql database. When I specifically defined the tables I wanted to export using -classes="...", the error went away.

For example:

symfony propel:data-dump --classes="{table},{tablew},..."  fixtures.yml

Upvotes: 1

Related Questions