I basically have an issue that I’m wondering about, first though I will explain my scenario. I have “pages” and associated with each page are multiple “content modules”, stored in a pages and content table with a one to many relationship.
I could simply do everything I need by making a new model every time I need data but if I’m not mistaken this will use another query every time I need a piece of data when I could load a page and all the content in one go.
So my question is, say I have an array of all the content models in $content, ie:
Is there any way I can get it to generate an associative array using a database field as the key when it returns an array of results?
The thing is that I know all the content content rows for a page need to be used so it would be more efficient to fetch them all at once, but I don’t know how to access a row specifically from the pre-prepared array of rows based on a field.
Would the best way to do this be to just use a foreach statement to construct an array from the returned database array? Or is there a cleaner way?