Welcome Guest, Not a member yet? Register   Sign In
What is the best practice for querying a DB with 2 or 3 tables
#1

I have 3 tables:

BlogTable
BlogTagTable - Record one row for each tag in a blog post. Eg. if 3 tags, will be three lines in the db with reference to the tagId and BlogId.
TagTable - master list of possible tags with names.

When I querybuild to get all blog posts I could make one large join. This will produce a large result though. For instance, if a blog post has 10 tags, I would get 10 lines back. I would assume that all query code would go in the BlogModel even if querying tags, right?

Alternatively, I could query the Blog table first, get all blog posts and then for each blog post, query the tags used. Would both query code go in BlogModel or just the blog query in BlogModel and tag query in TagModel?

I also thought of method chaining like getBlog()->withTags()->paginate() etc; I would pass the blog object to tags and then add an array of used tags in the blog post. What are your thoughts?

I appreciate all of your comments or suggestions!
Reply


Messages In This Thread
What is the best practice for querying a DB with 2 or 3 tables - by spreaderman - 06-12-2024, 07:17 PM



Theme © iAndrew 2016 - Forum software by © MyBB