Welcome Guest, Not a member yet? Register   Sign In
Many-to-Many Relationships & Active Record Class
#1

[eluser]Chris Newton[/eluser]
I'm trying to build the results of a many-to-many relationship between 3 tables using the active record class. I maintain a news table containing all of the news item, a category table containing all of the category names & ids, and a join table, containing all of the news_ids & their respective category_ids.

I know how I could do this with standard PHP, but I'm trying to wrap my brain around the best way / best syntax for the active record class. I'm trying to build this many-to-many relationship without a lot of looping and I haven't come up with a working solution yet.

Table 1: ci_news
id,subject,content,date

Table 2: ci_news_to_categories
news_id
category_id

Table 3: ci_news_categories
id,name

Each news item may have multiple categories which is why I need the join table, rather than just adding category_id to the news table.

Does anyone have any working examples of a model that references this type of relationship?


Messages In This Thread
Many-to-Many Relationships & Active Record Class - by El Forum - 11-27-2007, 09:00 AM
Many-to-Many Relationships & Active Record Class - by El Forum - 11-27-2007, 10:07 AM
Many-to-Many Relationships & Active Record Class - by El Forum - 11-27-2007, 10:16 AM
Many-to-Many Relationships & Active Record Class - by El Forum - 11-27-2007, 11:32 PM
Many-to-Many Relationships & Active Record Class - by El Forum - 11-28-2007, 02:44 AM
Many-to-Many Relationships & Active Record Class - by El Forum - 11-28-2007, 03:00 AM
Many-to-Many Relationships & Active Record Class - by El Forum - 11-28-2007, 08:41 AM
Many-to-Many Relationships & Active Record Class - by El Forum - 11-28-2007, 09:00 AM
Many-to-Many Relationships & Active Record Class - by El Forum - 11-28-2007, 10:07 AM
Many-to-Many Relationships & Active Record Class - by El Forum - 11-28-2007, 11:02 AM
Many-to-Many Relationships & Active Record Class - by El Forum - 11-28-2007, 11:49 AM
Many-to-Many Relationships & Active Record Class - by El Forum - 11-28-2007, 12:33 PM
Many-to-Many Relationships & Active Record Class - by El Forum - 11-28-2007, 08:46 PM
Many-to-Many Relationships & Active Record Class - by El Forum - 12-05-2007, 11:02 PM



Theme © iAndrew 2016 - Forum software by © MyBB