Express Custom Template Not Working with a Many to Many Association

Permalink
So I was trying to build a express detail template following the example in the 3rd express video. However I am building a set of books that can be in multiple categories, so my associations are a many to many instead of a one to many like in the video. Once I use a many to many association the
$entry->getBooks()
method does not work.

Any ideas why this is?

Here is the related documentation I was following:http://documentation.concrete5.org/developers/express/using-the-exp...

 
srs04 replied on at Permalink Reply
Upgraded from 8.0.2 to 8.0.3 still does not work. Anyone have any ideas? The documentation is pretty light so I don't know what the issue may be.

Thank You!
jakubt replied on at Permalink Reply
I have same problem and I found ugly, but working hack
$x = $entry->getAssociations()->offsetGet(0);
if($x) { $assocEntries= $pom->getSelectedEntries(); } else { $assocEntries = []; }

The empty array is not strictly necessary, but it allows to continue with things like this

foreach ($assocEntries as $e) {
  $e -> getBookName();  
  ....
}


I have no idea if it works in all cases, but it works for me - I am using it qith many to many assoc at the moment. BTW strange thing is that $entry->getAssociations()->get(<key>) does not work for any <key> I could imagine and I do not know how to find out what are all keys of PersistentCollection clas (in this case $entry->getAssociations() ). Concrete5 is beautiful, but there is abig lack of documentation and what surprises me most, that even in the source code does not contain some brief basic comments.