If I fetch an object like 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 is the output I 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 I modify the original code to change a value before dumping:
$object = $q->findPk(1);¬
$object->setStatusId(5);
The resulting output doesn't include the Status
element, only the 'StatusId'. I can of course get this back with $object->getStatus()
before using toArray()
but is there a way to do this generically?
I was wondering if there's a way to check if a value is a foreign key so that if it is I can automatically get getWhatevers()
after that value is set, instead of hard-coding them. Or maybe there's a better way?
My other option is to override toArray
but the scope for errors and amount of maintenance as a database changes here would have to be considered.