You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to store the return value of a method in an ActiveRecordInterface object into a virtualColumn on that object at hydration time so that it's included in the JSON formatter, and I'm having some trouble with two things.
When I access this with a standard query from the associated FamilyQuery class and run through the toJSON parser, I receive a fully hydrated object in JSON format (including fully hydrated Person Objects:
Is there a way to prevent the entire contents of the related object from being formatted in the JSON output? I'd prefer to have only the Family object hydrated, and the value for FamilyString - not an array of each family member.
Issue 2:
With a table Pledges related to the Family table, I don't want to hydrate the entire Family object - I'm only interested in the FamilyString virtual column that was added during the Family object's hydration.
If I use ->joinWithFamily(), the entire family object (including the FamilyString) virtual column is hydrated and included in the resultant JSON output.
@benbankes suggested that I, instead of attempting to add the field at hydration time, add the field when the object is serialized into an array.
The resultant code on the Family model/class looks something like this: We are overriding the parent's toArray() method; invoking the parents method, and then altering the parent's return before passing the array to the application:
public function toArray()
{
$array = parent::toArray();
$array['FamilyString']=$this->getFamilyString();
return $array;
}
Since the native toJSON() method actually calls the object's toArray() method, this solution worked for me to provide the calculated field I required to my API endpoint without including client-side manipulation, neither in the browser, nor in the client-code that invokes the Propel models.
Scenario
I'm trying to store the return value of a method in an ActiveRecordInterface object into a
virtualColumn
on that object at hydration time so that it's included in the JSON formatter, and I'm having some trouble with two things.The only seemingly-relevant, but not totally clear help I've found is this: http://howcanfix.com/14251/symfony-app-how-to-add-calculated-fields-to-propel-objects
First, the Object model code:
Full code here: https://github.com/ChurchCRM/CRM/blob/master/src/ChurchCRM/model/ChurchCRM/Family.php
and related schema (simplified)"
Full Schema here: https://github.com/ChurchCRM/CRM/blob/master/propel/schema.xml
Issue 1:
When I access this with a standard query from the associated
FamilyQuery
class and run through thetoJSON
parser, I receive a fully hydrated object in JSON format (including fully hydratedPerson
Objects:Is there a way to prevent the entire contents of the related object from being formatted in the JSON output? I'd prefer to have only the Family object hydrated, and the value for FamilyString - not an array of each family member.
Issue 2:
With a table
Pledges
related to theFamily
table, I don't want to hydrate the entire Family object - I'm only interested in theFamilyString
virtual column that was added during the Family object's hydration.If I use
->joinWithFamily()
, the entire family object (including the FamilyString) virtual column is hydrated and included in the resultant JSON output.If I use
->joinFamily()
, there does not seem to be a way to select only theFamilyString
Virtual column.Is there a way to select from a joined table, a single virtual column that was added during the related object's hydration for inclusion in
toJSON()
?The full set of what I'm trying to accomplish is here: ChurchCRM/CRM#2564
The text was updated successfully, but these errors were encountered: