6

I have Book schema, that has a component link to similar books. One of the similar books, has a component link back to original component. In such way I got circular reference.

When publishing this component with DXA 2.0 TBBs expandLinkDepth parameter handles it nicely, and as result I got only couple of levels included in JSON.

However my main issue is on webapp side, it is failing during model mapping.

Book model has next property:

[SemanticProperty("s:similar_books")]
public List<Book> SimilarBooks { get; set; }

Default DataModelBuilder successfully maps couple of levels of Books to my property, however the last level that was restricted by TBB expandLinkDepth is failing with such message:

Unable to map field 'SimilarBooks' to property Book.SimilarBooks of type ...

It fails on this line of BuildEntityModel method of DefaultModelBuilder, because SchemaId is null.

SemanticSchema semanticSchema = SemanticMapping.GetSchema(entityModelData.SchemaId, localization);

Probably we can enhance DXA to avoid exception, however:

How should we handle such circular reference situations in general with DXA Models?

Thanks!

3
  • Hmmm. Sounds like an issue to be reported on GitHub Commented Jun 15, 2018 at 6:21
  • Do you really want recursively expanded Entity Models in the first place? You could also use a property of type List<Link> to get the similar books as links to other pages. Commented Jun 15, 2018 at 6:24
  • @RickPannekoek Yes, I need expanded EntityModel, but only for the first level. I don't need it recursively for all levels. Ok, will report it. Thank you! Commented Jun 15, 2018 at 23:26

1 Answer 1

6

Although this sounds like a defect in the DXA Framework in general, I think a work-around is possible, since you mentioned you don’t need more than one level expansion:

Create a new View Model Type, say SimilarBook, which maps to the same Schema/Properties as Book, but don’t let if have a SimilarBooks property.

Let the Books.SimilarBooks propery be of type List<SimilarBook>. This effectively breaks the recursive nature of the association.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.