Welcome Guest, Not a member yet? Register   Sign In
One to many relationship displayed on a single page
#1

[eluser]lukeinjax[/eluser]
I'm new to CodeIgniter and I'm trying to figure out the best way to go about something that I'm sure has been done a thousand times before, but I can't seem to find any info on it. Here's what I have:

Submissions table - one row per submission
Tags table - many rows per submission

I want to show all submissions on a single page and each submission can have many tags. So, when I run a query for all submissions and each submission's tags by joining the two tables on submission_id, I get several rows for each submission (one for each tag). In this case, I can't simply run them through a foreach loop in my view because I would get repeating submissions. I would have to have some type of logic to say "if the submission id <> previous submission id...". This seems like more logic than I should have in my view.

I was thinking that, in my model, I could query the submissions table, then loop through the results, creating a submission object for each row, then query the tags table to get the tags for each submission and add them to the submission object. Each submission object would be added to an array that would be returned to the controller and then passed to the view. Then I could call a method in the submission object from within the loop in my view which would return all the tags in a single formatted string. This would result in much less code in my view.

So, the issue is that I'm not sure where I would store the object class within the CodeIgniter folder structure (or if it should be stored elsewhere). Also, how would I reference it in my model and my view?

The only problem with the second method (the one using the custom submission class) is that it will be very database intensive (one call to get all the submissions and then another call for each of the submissions against the tags table). I'm thinking that there may be an entirely better and more simple way to do this that I'm just not seeing, so if I have analyzed myself into a corner, please let me know. Otherwise, let me know if I'm on the right track. Smile Thanks!
#2

[eluser]billmce[/eluser]
Two years and no reply? Sheesh.
I could really use an answer to this question too ...




Theme © iAndrew 2016 - Forum software by © MyBB