Shayne Precious Tue Nov 06 03:25:16 -0500 2012

Subject: associations help

I have a problem with setting up relationships between classes in PHP.ActiveRecords that I hope someone can help me with.

I have three tables in a db as follows:

Users =====
site_id (fk to sites)

sites =====

site_admin ==========
site_id (fk to sites)
user_id (fk to users)

- Users have a 'home' site, hence the fk directly to sites
- Some users are Admins who will have the ability to admin multiple sites, hence the 'site_admin' table

I understand I will have 3 classes/models: User, Site and SiteAdmin but I cannot figure out how to implement the php.ActiveRecord associations between these classes.

I can get the 'many-to-many' relationship between user and site through siteadmin working OR I can get the one to many directly from user to site but there is a conflict when trying to get them both working together.

Working code I have is as follows:

(NOTE: using mysql, php5.3, wampserver apache 2.42 and PHP-AR 0.0.2 on CI 2.1.3 using sparks)