Closed javer closed 11 years ago
a2ff29533edecd3869ca3a1903c41f5c833c9916 doesn't exists anymore. AFAIR column constants are always(?) uppercase so.. @javer I just need some example/test to prove this issue, you got any?
I mean this commit: https://github.com/propelorm/Propel/commit/a2ff29533edecd3869ca3a1903c41f5c833c9916
With this schema:
propel:
news:
id: ~
title: { type: varchar, size: 255 }
category:
id: ~
title: { type: varchar, size: 255 }
news_by_category:
_attributes: { isCrossRef: true }
news_id: { type: integer, required: true, primaryKey: true, foreignTable: news, foreignReference: id, onDelete: cascade, onUpdate: cascade }
category_id: { type: integer, required: true, primaryKey: true, foreignTable: category, foreignReference: id, onDelete: cascade, onUpdate: cascade }
and after building model and filters we have:
abstract class BaseNewsFormFilter extends BaseFormFilterPropel
{
public function setup()
{
$this->setWidgets(array(
'title' => new sfWidgetFormFilterInput(),
'news_by_category_list' => new sfWidgetFormPropelChoice(array('model' => 'Category', 'add_empty' => true)),
));
$this->setValidators(array(
'title' => new sfValidatorPass(array('required' => false)),
'news_by_category_list' => new sfValidatorPropelChoice(array('model' => 'Category', 'required' => false)),
));
$this->widgetSchema->setNameFormat('news_filters[%s]');
$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
parent::setup();
}
public function addNewsByCategoryListColumnCriteria(Criteria $criteria, $field, $values)
{
if (!is_array($values))
{
$values = array($values);
}
if (!count($values))
{
return;
}
$criteria->addJoin(NewsByCategoryPeer::NEWS_ID, NewsPeer::ID);
$value = array_pop($values);
$criterion = $criteria->getNewCriterion(NewsByCategoryPeer::category_id, $value);
foreach ($values as $value)
{
$criterion->addOr($criteria->getNewCriterion(NewsByCategoryPeer::category_id, $value));
}
$criteria->add($criterion);
}
public function getModelName()
{
return 'News';
}
public function getFields()
{
return array(
'id' => 'Number',
'title' => 'Text',
'news_by_category_list' => 'ManyKey',
);
}
}
Look at NewsByCategoryPeer::category_id. Before commit https://github.com/propelorm/Propel/commit/a2ff29533edecd3869ca3a1903c41f5c833c9916 it looked like NewsByCategoryPeer::CATEGORY_ID, as it should be.
Different column peer name can be set manually in schema so we couldn't rely on _strtoupper_ and column name.
I've used Peer::translateFieldName()
since it looks like the proper way to do that.
Thanks!
Fixed column constant case when generating BaseModelFormFilter because of changed case sensitivity of columns in commit a2ff29533edecd3869ca3a1903c41f5c833c9916.
Now generated constant looks like ModelPeer::COLUMN_NAME instead of ModelPeer::column_name, which throws fatal error 'Undefined class constant' because of PHP constant case-sensitivity.