johnmerlino Posted April 13, 2011 Share Posted April 13, 2011 Hey all, I have a relationship where a zone has many posts and a category has many zones but a zone can also have many categories. The zones are basically parts of a page, such as the main area and sidepanel stored in database as records with name fields such as 'panel' and 'main'. There's a serious flaw right now and I would like to know the best solution to address it. Right now I access the posts of a zone of a category like this: $category->zone->get()->post->get(); The above ends up displaying all the posts in the database for any given category because when category is selected, it searches for the associating zones, and then selects all posts related to those zones, which is wrong. i want to select all posts of the zones associated with that particular category. Current database: posts id zone_id zones id name categories_zones id zone_id category_id categories id What should I do? Add a category_id column to the posts table and relate the post directly to the category as well as directly to the zones table so the post table would have two foreign keys: category_id and zone_id Would this be the most effective thing to do given my requirements? Thanks for response. Quote Link to comment https://forums.phpfreaks.com/topic/233556-all-my-posts-are-being-generated-for-all-the-categories/ Share on other sites More sharing options...
johnmerlino Posted April 13, 2011 Author Share Posted April 13, 2011 I decided to create the category_id in posts. Makes things a whole a lot easier. Quote Link to comment https://forums.phpfreaks.com/topic/233556-all-my-posts-are-being-generated-for-all-the-categories/#findComment-1200943 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.