/** * Create form field from relation. * * @param \RelationMap $relation * @return Entity */ public function createFieldFromRelation(\RelationMap $relation) { $name = 'relation__' . strtolower($relation->getName()); $toMany = self::isRelationTypeToMany($relation->getType()); $options = array('id' => $name . rand(), 'type' => $toMany ? 'multiplechoice' : 'choice', 'label' => $relation->getName() . ($toMany ? 's' : ''), 'choices' => $this->getChoicesFromRelation($relation)); $this->createField($name, $options); }
/** * Set relation value from instance. * * @param BaseObject $instance * @param RelationMap $relation * @param mixed $value */ protected function setRelationValue(BaseObject $instance, RelationMap $relation, $value) { switch ($relation->getType()) { case RelationMap::ONE_TO_MANY: case RelationMap::MANY_TO_MANY: $setter = 'set' . $relation->getPluralName(); $otherTable = $relation->getRightTable()->getPhpName(); $instance->{$setter}(PropelQuery::from($otherTable)->findPks($value)); break; case RelationMap::MANY_TO_ONE: case RelationMap::ONE_TO_ONE: $setter = 'set' . $relation->getName(); $otherTable = $relation->getRightTable()->getPhpName(); $instance->{$setter}(PropelQuery::from($otherTable)->findPk($value)); break; } }