Skip to content
This repository has been archived by the owner on Dec 13, 2021. It is now read-only.

Support for Relations? #36

Closed
leekelleher opened this issue Mar 4, 2015 · 11 comments
Closed

Support for Relations? #36

leekelleher opened this issue Mar 4, 2015 · 11 comments

Comments

@leekelleher
Copy link
Collaborator

@Hendy mentioned this in the Gitter chatroom.

Consider adding support for Relations.

[RelationType("relationTypeAlias")]
public object RelatedItems { get; set; }

Then Ditto could get the related node IDs for the associated IPublishedContent node and pass the value to the POCO property.

e.g. @Model.RelatedItems could return a IEnumerable<IRelation> object type?

Details of the IRelation interface can be found here.

Then for more complex types a custom TypeConverter can be used:

[RelationType("relationTypeAlias")]
[TypeConverter(typeof(RelationsTypeConverter))]
public IEnumerable<IPublishedContent> RelatedItems { get; set; }

Then the custom RelationsTypeConverter can work out how to convert an IEnumerable<IRelation> into IEnumerable<IPublishedContent>.

@leekelleher
Copy link
Collaborator Author

One concern might be that the IRelationService call hits the database? Do we know if Umbraco core caches the result in memory?

@mattbrailsford
Copy link
Collaborator

I'd say make sure to use the Lazy< T> class so that they are only loaded when someone tries to access them. Don't want to slow down general Ditto for an edge case.

@leekelleher
Copy link
Collaborator Author

👍 on Lazy<T>.

At this stage, I'm only noting this as an idea. If we think it is too much of an edge case, then we can shelve it.

@JimBobSquarePants
Copy link

I've just pushed a new branch for you to look at. feature/allow-relations

This contains a change to the PublishedContentContext class.

The context PropertyDescriptor property now points to the property on the target class that is currently being converted. This allows us to parse any attributes on that property from within a custom TypeConverter Using the PropertyDescriptor.Attributes property.

I think that would be enough to allow what is needed. Am I correct?

@leekelleher
Copy link
Collaborator Author

You're correct!

Actually thinking about it, this might remove the need for having my UmbracoDictionaryValue attribute, as it could be handled the same way - within a specialised/custom TypeConverter.

@Hendy
Copy link

Hendy commented Mar 4, 2015

@JimBobSquarePants perfect :)

@leekelleher how about a caching factory, that'll supply 'clean' POCOs (ones that don't inherit from PublishedContetModel) so once slow relations are inflated, they are in the object graph cache

@leekelleher
Copy link
Collaborator Author

@Hendy - we already have pre/post event hooks during the conversion - see EventHandlers.cs source. You could roll your own? (Unless I'm missing a bigger benefit?)

@JimBobSquarePants
Copy link

Awesomesauce!
@leekelleher Shifting that into it's own TypeConverter would clean up the GetTypedProperty method a little anyway. It seems a good fit also and we only get strings from that don't we?

@leekelleher
Copy link
Collaborator Author

Cool. I'll look to remove the UmbracoDictionaryValue attribute (and associated code). I'll branch it off so that I can rework it later.

@JimBobSquarePants
Copy link

Ok coke... Should be simple enough too do. We still on for a release tomorrow?

@leekelleher
Copy link
Collaborator Author

Yeah, should be good for tomorrow!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

4 participants