0

<td><?= PersoonHasStdtaak::model()->findByPk(array('idPlanning' => $modelPlanning->idPlanning, 'idStdTaak' => $modelStdtaak->idStdTaak))->idPersoon0->Naam ?></td>

I've got this. Somehow when I let it just print it without the idPersoon0->Naam it prints regulary a composite primary key in this form #-#-# for example 1-2-3 where 1 represents the Person 2 represents the Planning and 3 represents the Taak.

Why does it give me the "Trying to get property from non-object."?

Highmastdon
  • 6,960
  • 7
  • 40
  • 68
  • "idPersoon0" is a field in the database? cause if idPersoon is an array with all the ids then to acces its value you should do "idPersoon[0]->Naam" – darkheir Nov 29 '12 at 14:13
  • I'ts a property holding the whole `Persoon` object. According to other posts on this should be possible: http://stackoverflow.com/questions/7567686/yii-cactiverecord-find – Highmastdon Nov 29 '12 at 14:43
  • May be try to do 2 lines: $model = PersoonHasStdtaak::model()->findByPk(array('idPlanning' => $modelPlanning->idPlanning, 'idStdTaak' => $modelStdtaak->idStdTaak)); $model->idPersoon0->Naam; Just to see if the error comes from the first one or the second one. Then it'll be easier to determine what causes the "Trying to get property from non-object" – darkheir Nov 29 '12 at 15:12
  • Thanks for the hint. Yes I've done that, but still got the same error. Would be nice if it said: "Cannot retrieve property from null-object" but i've found it ;) – Highmastdon Nov 29 '12 at 18:03

1 Answers1

0

Okay.. Stupid mistake by "ME"

I was looping through something where it's possible that there is no record with those combination of primary keys. Therefore it returns NULL. And from a NULL-object its not possible to get any properties :) (doH)

Good luck for anyone finding this. Look out if it returns a NULL object.

Highmastdon
  • 6,960
  • 7
  • 40
  • 68