Search code examples
phpsymfony1doctrinesymfony-1.4propel

getRelation in Propel


News: id name category_id

Category: name If i have relation in Doctrine then i have use:

$news->getName(); $news->getCategory()->getName() or simply $news->getCategory() instead of $news->getCategoryId()

but in Propel this doesnt working. Is possible this? I must create own function in model?


Solution

  • Does your schema.yml file have the correct foreign key reference for the relation between category and news? I've submitted an example below as a reference. If you use this and build your model classes the call to the relation should work just fine.

    news:
      _attributes: { phpName: News }
      id: { phpName: Id, type: INTEGER, size: '11', primaryKey: true, autoIncrement: true, required: true }
      name: { phpName: Name, type: VARCHAR, size: '50', required: false }
      category_id: { phpName: CategoryId, type: INTEGER, size: '11', foreignTable: category, foreignReference: id, onDelete: cascade, onUpdate: cascade }