Maybe this is pretty basic and that's the reason why I haven't found anything for this…
Here is my table structure:
object
id | type | …
1 | brand | …
2 | project | …
3 | brand | …
meta
id | object | name | value
1 | 1 | name | adidas
2 | 1 | color | blue
3 | 3 | name | telekom
4 | 3 | color | pink
I want to fetch the data similar to:
SELECT o.*, EACH( m.value as m.name ) FROM object o LEFT JOIN meta m ON m.object = o.id GROUP BY id
which should result in:
id | type | … | name | color
1 | brand | … | adidas | blue
2 | brand | … | telekom | pink
Any ideas? This have to be dynamically because the amount of meta rows and their keys can be different.
I think this is pretty close to the table structure of WordPress (posts & postmeta) … do they fetch their meta on the initial query or do they fire a second one for each result selecting the meta?