php - Can I maintain hydration after updating an object with Propel? -


if fetch object so:

$q = orderreturnquery::create()     ->joinwith('type')     ->joinwith('status')     ->usestatusquery()         ->joinwith('email')         ->enduse()     ->joinwith('priority'); $object = $q->findpk(1); var_dump($object->toarray(tablemap::type_phpname, true, [], true)); 

this output get:

array (size=14)   'id' => int 1   'typeid' => int 3   'statusid' => int 2   'priorityid' => int 1   'orderid' => int 234567   'customerid' => int 5   'initiated' => string '2016-03-02t01:11:12+00:00' (length=25)   'initiator' => int 2   'freepostagelabel' => boolean true   'lostinpost' => boolean false   'suppressemail' => boolean true   'type' =>      array (size=4)       'id' => int 3       'title' => string 'title 3' (length=7)       'priority' => int 3       'orderreturns' =>          array (size=1)           0 => string '*recursion*' (length=11)   'status' =>      array (size=6)       'id' => int 2       'emailid' => int 2       'title' => string 'title 2' (length=7)       'priority' => int 2       'email' =>          array (size=5)           'id' => int 2           'subject' => string 'subject 2' (length=9)           'plaintext' => string 'plain text 2' (length=12)           'html' => string 'html 2' (length=6)           'statuses' =>              array (size=1)               0 => string '*recursion*' (length=11)       'orderreturns' =>          array (size=1)           0 => string '*recursion*' (length=11)   'priority' =>      array (size=4)       'id' => int 1       'title' => string 'title 1' (length=7)       'priority' => int 1       'orderreturns' =>          array (size=1)           0 => string '*recursion*' (length=11) 

now if modify original code change value before dumping:

$object = $q->findpk(1);¬ $object->setstatusid(5); 

the resulting output doesn't include status element, 'statusid'. can of course $object->getstatus() before using toarray() there way generically?

i wondering if there's way check if value foreign key if can automatically getwhatevers() after value set, instead of hard-coding them. or maybe there's better way?

my other option override toarray scope errors , amount of maintenance database changes here have considered.

when you're calling toarray method fourth parameter can set true in order make model retrieve related objects

$object->toarray(tablemap:: type_phpname, true, [], true); 

edit: @darkbee noted in comments calling toarray correct parameters, why aren't getting related objects in array representation? answer resides in step of code

$object->setstatusid(5) 

you're updating object without updating database related record, doing propel isn't able retrieve correct related object, avoid behavior can set full status object instead of sole id, eg:

$object->setstatus(statusquery::create()->findpk(5)); 

by doing have correct status object information in array representation, careful (as said), probably, doesn't reflect database state.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -