Keith Morris Mon Jan 30 20:37:37 -0500 2012

Subject: Self association problem

Hey,

I'm just getting started with php-activerecord and I was hoping someone could help me with an issue. I'm trying to create a utility application to track application dependencies in our hosting environment. Here is the scenario. I have many applications. Each application can have many other applications that depend on it. In addition, there may be many applications that this app depends on. I have two tables:

apps:
id
appname

And a 'dependents' table:
dependents:
id
app_id
dependent_id

What I'd ultimately like to be able to do is call the following in order to get an array of dependent app objects:

1 App::find(1)->dependents;

And the following in order to get providers (an array of app object that this app depends on which would still be joined through the dependents table):

1 App::find(1)->providers;

I haven't gotten far, but I've tried the following just to get started but can't get any results:

1 class App extends ActiveRecord\Model
2 {        
3     static $has_many = array(
4         array('dependents'),
5         array('apps', 'through' => 'dependents')
6     );
7 }

I'm sure this will be a combination of $has_many (through) but I can't seem to get it working. Any assistance anyone could offer would be very much appreciated.

Keith