Search code examples
propel

Get fields with one relation


test:
  _attributes:   { phpName: Test }
  name:    { type: varchar, size: 100 }
  one_id:  { type: INTEGER, foreignTable: second, foreignReference: id}
  two_id:  { type: INTEGER, foreignTable: second, foreignReference: id}


second:
  _attributes:   { phpName: Second }
  name:          { type: varchar, size: 100 }

In Doctrine I can get this with $test->getSecond1(); and $test->getSecond2(); but in Propel this doesnt work. How can I get two other fields from one relation?


Solution

  • To get the right associated object, when we have two foreign references to the same foreign table, we need to use:

    $test->getSecondRelatedByOneId()
    $test->getSecondRelatedByTwoId()
    

    Then we get foreign references to Second in Test object with:

    $test->getOneId()
    $test->getTwoId()
    

    I use only Propel at the moment, so sorry if I misunderstood.