Highlighted

content fragment model relationships

Avatar

Avatar

will_qiao

Avatar

will_qiao

will_qiao

13-06-2018

Hello,

How two content fragment models can be setup to manage parent-child kinds of relationship? Let's say I have an account model and a product model. An account can have multiple products. A product must be attached to an account. I want to create services that wrap around the two models to serve different apps.

It will be nice the content fragment model can support content fragment creations so that child fragments will be instantiated under parent fragment instances. With that, the customized exporters/services will traverse the content fragment nodes and build corresponding JSONs. Basically node structures will make CRUD ops easier.

Thanks in advance.

Will

Replies

Highlighted

Avatar

Avatar

bsloki

MVP

Total Posts

1.9K

Likes

172

Correct Answer

544

Avatar

bsloki

MVP

Total Posts

1.9K

Likes

172

Correct Answer

544
bsloki
MVP

13-06-2018

Hi Will,

which version of AEM are you using?

Based on 6.4, I can think of below 2 options

Approach 1:

Using 'Associated Content' approach

1. Create the account model and product model content fragments.

2. Create collections of product model fragments and associate that collection to an account model fragment.

3. Then when you query a account model fragment, you can write a service to get the associated content data model.

Approach 2:

Using 'Tags'

1. Create a product tags

2. For the product model fragments, add that particular product tag.

3. For the account model fragments, add all the associated product tags

4. Then you query based on the tags.

Thanks,

Lokesh

Avatar

Avatar

will_qiao

Avatar

will_qiao

will_qiao

22-06-2018

Thanks Lokesh,

I like approach 1. I suppose the associated content is established through a field called <Content Reference> from parent CF to child CF. Parent and child CFs can locate at the default locations or any folders under /content/dam/<project>

Approach 2 is more suitable for loosely coupled relationships in respect of CF locations, types ...

I think there is another option.

Approach 3: leverage CF locations under /content/dam/<project>/... Before creating a collection of child CFs, manually create a single:Folder that matches the parent CF name first(nice to automate this). Then create the collection under that folder.

regards

Will