AnsweredAssumed Answered

How to know which relationship to load in a logic hook?

Question asked by Gaelle Fernandez on Jun 27, 2014
Latest reply on Jun 30, 2014 by Gaelle Fernandez
Hello everybody,

I'm coming to a dead end in my logic hook. (and i'm in a hurry!!)
A Meeting should be related to an account. I know you can do that by the original relationship and original Account field in Sugar 7.2 (but i've encountered big issues to find how to get the id of the account...)

Anyway, i've added an account related field to my Meeting module.
I know this is bad and well, as expected, when saved, the meeting is not related to the accounts ( aka does not appear in Meeting's subpanel under account module)..

Bezcause I have a "updateAccountWithMeetingField" logic hook, i thought it could be good to add the relationship between those two.

So i've wrote in my logic hook (called after_save in meetings):

$society->save();
$society->load_relationship('meetings');
$society->meetings->add($bean->id);
$society->save();

But it does not works. I've went to see in mysql and... i have two relationship tables, "meetings_accounts_1_c" and "meetings_accounts_2_c", which are both empty.

I think my code does not work because i'm not loading the right relationship. Yes, indeed, i've two relationships and none of them is called only "meetings_accounts".

I've tried to write (and same for 2_c):

$society->save();
$society->load_relationship('meetings_1_c');
$society->meetings_1_c->add($bean->id);
$society->save();

But it throws me the error that i'm calling "add" on a non object
So, THROUGH CODE, How do i possibly know which one to filled?
WHICH name should i put in load_relationship ???

Thanks a lot!

Outcomes