I'm working on a Zend Framework 2 application with a complex class (Foo
) having many levels of nesting (Foo.Bar
, Foo.Baz.Buz
etc.). The data is stored in a relational database (MySQL). On the application level it gets hydrate
ed to DataObject
s by the Zend\Hydrator\ClassMethods
.
To get all the data needed to build a Foo
DataObject
I use an SQL statement (wrapped by Zend\Db\Sql\Select
). As ResultSet
I get a big table like this:
id some_foo_attr bar_id some_bar_attr baz_id some_baz_attr buz_id some_buz_attr
-------------------------------------------------------------------------------
1 foo_value_a 1 bar_value_a 1 baz_value_a 1 buz_value_a
1 foo_value_a 1 bar_value_a 1 baz_value_a 2 buz_value_b
1 foo_value_a 1 bar_value_a 2 baz_value_b 3 buz_value_c
1 foo_value_a 1 bar_value_a 2 baz_value_b 4 buz_value_d
1 foo_value_a 2 bar_value_b 3 baz_value_c 6 buz_value_e
1 foo_value_a 2 bar_value_b 3 baz_value_c 7 buz_value_f
1 foo_value_a 2 bar_value_b 4 baz_value_d 8 buz_value_g
1 foo_value_a 2 bar_value_b 4 baz_value_d 8 buz_value_h
2 foo_value_b 3 bar_value_c 5 baz_value_e 9 buz_value_i
...
Now I have a problem to get this data to DataObject
s. What is an efficient way to do this? Or maybe I made a mistake a step before and should retrieve the data differently?