Hi, Iāve had a lot of issues getting custom modules to relate to each other in suitecrm. What Iāve done so far in this instance was create a module named āsales_bookingsā i deployed from the module builder and given a 1 to many relationship (1 account to many bookings).
This is the relationship definition from my vardefs in the sales_Booking cache folder (inside cache/modules/sales_Booking):
and Iāve used a before_save logic hook, the first two lines of the function are
5. $bean->load_relationship(āsales_booking_accountsā);
6. $account = $bean->sales_booking_accounts->getBeans();
in which the getBeans() line gets flagged in the apache2 error log but nothing from the suitecrm log with this error:
PHP Notice: Undefined property: AOD_IndexEvent::$sales_booking_accounts in custom/modules/sales_Booking/NameMove.php on line 6
PHP Fatal error: Uncaught Error: Call to a member function getBeans() on null in /var/www/html/goodgreekcrm/custom/modules/sales_Booking/NameMove.php:6
Iāve tried the usual QR&R and rebuilding relationships to see if maybe some auto-generated files havenāt been made yet but after reading through the working with beans section of the docs the relationship name looks right
No I created the relationship while the module was still in the module builder. I have set-up a new module for testing this and created the same type of relationship in studio after deploying and get the same error. Vardefs checks out so Iām not sure what the bean name is being checked against
Looking at my cached vardefs, I have the relationship named āaccounts_moves_moves_1ā which was made in studio. As a test I created a logic hook that tests the load_relationship and getBeans function here:
if ($bean->load_relationship(āaccounts_moves_moves_1ā)
{
//$account = $bean->accounts_moves_moves_1->getBeans();
}
else
{
$bean->description = āfailedā;
}
After running this I donāt receive a āfailedā in my description, it wasnāt until i changed the relationship name so I believe that it is loading the relationship. Once I uncomment the getBeans line I get the same error in the logs. This is on a brand new install of 7.11.18
PHP Notice: Trying to get property ānameā of non-object in /custom/modules/Moves_Moves/Name.php on line 8
This is when trying to use $bean->name = $account->name
So now the fatal errors have started just giving notices, but it still isnāt able to find the related bean. Iāve gone through the Working with Beans to make sure I was using the link name of the relationship but donāt see anything obvious hereā¦ Iāve worked through this issue a few months ago. Looking at my database i see a table named āaccounts_moves_moves_1_cā which Iāve tried using as the relationship name with no luck. But the table does include the ID name of the moves_moves record and the account - which I guess can be used to rope them together and pull fields but the docs show a much nicer way with getBeansā¦
I have solved this issue but not using the the preferred method. Here is my snippet in case anyone else has problems with this. It searches the table containing related records between Accounts and Moves_Moves and finds the account ID which is related to the current bean after they are selected
Just one thing. Based on my experience, itās not good idea to include DB information in your code. It is better to use SuiteCRM methods to avoid security issues and maintenance related problems. Take a look into this sample to see how DB information is called: