Skip to content
Advertisement

How to ignore fields when fetching results using Propel?

I need to ignore fields instead of select fields in fetch data or reverse select fields.

Is that possible? If yes, how?

Advertisement

Answer

Regarding to the documentation, it’s not possible: http://propelorm.org/reference/model-criteria.html#getting-columns-instead-of-objects

But you can do it on your own.

Built an array of your fields (based on your peer class) and remove those you don’t need when you build your query

$fields = MyTablePeer::$fieldKeys[BasePeer::TYPE_PHPNAME];

/**
   will give you (for example):

   array (
     'Id' => 0, 
     'Name' => 1, 
     'Content' => 2, 
   )
 */

// remove unwanted column
unset($fields['Name']);

$items = MyTableQuery::create()
  ->select(array_keys($fields))
  ->find();
}
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement