The resultSet Simple toArray does not executes the toArray method in each model and because of this, nor the jsonSerialize.
As I see it, Each model array should be returned using the toArray defined in it.
It is causing me a lot of problems with my API, since I must transverse each result to execute the jsonSerialize method by hand. Not so simple, since my jsonSerialize methods are fetching relationships and this relationships more relationships, each one with its own jsonSerialize.
Could be this be revised? Usually the "collections" are managed as "Composite pattern", so if i call toArray on a collection of items, it returns each item toArray.
In this way, I can rely on fetching objects, even an objects with relationships, and getting my defined jsonSerializeor toArray of each one of them.
In pseudocode:
// each robot model on jsonSerialize returns some properties and the robot parts
// when calling json_encode on a Robot Model, it returns the Robot jsonSerialize, and the robot parts jsonSerialize
// in this way I can call
json_encode(Robots::find())
//and get a pretty json of robots, each one with its parts , serialized in the way "robot parts" decide.