Search code examples
apostrophe-cms

Auto Join using (JoinByOne , JoinByArray)


Usually , user need to manually choose which pieces/pages that needed to join. For Example : enter image description here

Can it be programmatically join ? If some properties via cursor is available, then I want it to join with my current piece. Else , it will return null.

The main purpose is to not manually search/browse my piece. I need it to be Auto join / programmatically join without user need to browse the piece by themselves. If not , I have to enable sendmail to admin to tell that, "Your blog receives Likes ! Join it to your blog piece now !" . Something like that.


Solution

  • Take a look at how they do it here on self.beforeInsert:

    https://github.com/apostrophecms/apostrophe-samples/commit/7f0b2b90377be4c4be216c8213ca4783ed2ec656

    More info from the docs here on cursors:

    https://apostrophecms.org/docs/tutorials/intermediate/cursors.html