Projects and Accounts

I am trying to load all the accounts associated to a given project, but for some reason that relationship is not loadingā€¦ Any ideas?

Code Snippet:
$focus = new Project();
$focus->retrieve($_GET[ā€˜projectIDā€™]);

$focus->load_relationship(ā€˜projects_accountsā€™);
$accounts = $focus->projects_accounts->getBeans();
$GLOBALS[ā€˜logā€™]->fatal(print_r($focus, true)); // This shows the relationship and the accounts for the projectID passed
$GLOBALS[ā€˜logā€™]->fatal($focus->name);
foreach ($focus->projects_accounts->getBeans() as $account)
{
$GLOBALS[ā€˜logā€™]->fatal($account->name);
}

This errors out as $focus->projects_accounts->getBeans() is erroring out with Call to a member function getBeans() on a non-object.

As this is a standard relationship not a custom one use accounts not projects_accounts.

Try:


$focus->load_relationship('accounts');

Hi vishmehra,

I think the id of project is not set properly hereā€¦

$focus->retrieve($_GET);

The $_GET will give the array of all the query-string parameters not only the Project ID, so it will be solved if you pass proper project id.

Try

$focus->retrieve($_GET[ā€œrecordā€]);