01-06-2016, 02:51 PM
I have a array that describe a database table and it's relations.
Assume we have a products table with following fields:
and based on the table I create a object with the details.
How can I loop this array in view so I can get the labels to create a table with the following thead ordered by position?
Column1 | Category Name | Column2 | Column Three | Image Name
When merging the arrays must check if a field from main table has same name with from relation table and if yes add a suffix.
Assume we have a products table with following fields:
- product_id
column1
column2
column_three
and based on the table I create a object with the details.
PHP Code:
Array
(
[pk] => product_id
[Fields] => Array
(
[column1] => stdClass Object
(
[Position] => 1
[Label] => Column1
)
[column2] => stdClass Object
(
[Position] => 3
[Label] => Column2
)
[column_three] => stdClass Object
(
[Position] => 4
[Label] => Column Three
)
//and here are the relations
[Relations] => Array
(
//the field category_name from category model
[category_name] => stdClass Object
(
[Position] => 2
[Label] => Category Name
[Model] => category
[Relation] => belongs_to
[PK] => id_categorie
)
[image_name] => stdClass Object
(
[Position] => 5
[Label] => Image Name
[Model] => image
[Relation] => has_one
[PK] => image_id
[Through] => product_id
)
)
How can I loop this array in view so I can get the labels to create a table with the following thead ordered by position?
Column1 | Category Name | Column2 | Column Three | Image Name
When merging the arrays must check if a field from main table has same name with from relation table and if yes add a suffix.