Programmatically Add Association to existing Express Object

Hey Folks,

So I’m reading through the documentation and so far as I can find, I’m only seeing examples of how to add an Association to an Express Object at creation when doing so programmatically.

I’m trying to figure out how to add (or modify) an Association once the Express Object is already made, programmatically.

Can anyone point me to this? I have a feeling this is an area for documentation to be improved @andrew :wink:

Okay so I think I’ve found my own answer, and please anyone correct me if I’m doing it wrong here, but…

===
use \Concrete\Core\Express\ObjectAssociationBuilder;

$objFirst = Express::getObjectByHandle(‘first_object_handle’);
$objSecond = Express::getObjectByHandle(‘second_object_handle’);
$objAssocLOL = ObjectAssociationBuilder::addManyToMany($objFirst, $objSecond);

===

Now, I’m not entirely sure if I need to have the "$objAssocLOL = " part, but it seems to work.

I also want to add that this association stops existing if I comment out the line containing “ObjectAssociationBuilder…”. And while this Association is present, clicking on the Association in the Dashboard doesn’t actually show any details about the Association, it actually just takes the user back to the list of Express Objects. Which is a touch annoying, as you can’t review the nature of the Association from the Dashboard at all (even if it’s just a read-only function).

So… yay! Hopefully this helps a future $human.