Support for query datasources?
I noticed in the GetModel processor that the following occurs:
var item = scContext.Database.GetItem(renderingItem.DataSource);
This works fine with path/guid datasources but when using a query type datasource this doesn't resolve and ends in the Model being NULL. Are there plans to support for example @inherits GlassView<IEnumerable<IGlassBase>> ? Where you can have a datasource like: template:{f68f13a6-3395-426a-b9a1-fa2dc60d94eb};+location:{13D6D6C6-C50B-4BBD-B331-2B04F1A58F21} ?
In the GetFromField(Rendering rendering, GetModelArgs args) method there's this part:
else if (rendering.Item == null)
{
return null;
}
This code needs to be adapted additionally to support the idea. Checking the rendering.Item will always result in NULL when a complex datasource is used. I have created a version of the GetModel processor that is capable of retrieving the first item of a complex datasource. I have yet to look into supporting IEnumerable type Models. I used the DataSourceHelper from this article by John West: http://www.sitecore.net/Learn/Blogs/Technical-Blogs/John-West-Sitecore-Blog/Posts/2013/05/Sitecore-7-Data-Sources-Part-6-Access-Multiple-Data-Source-Items-from-MVC-Views.aspx
Ivan
Thanks I will take a look
Mike
There are challenges with this - you can theoretically build a datasource that can return different types of models/items. Is there a way to restrict the type of items that can returned in a datasource query?
Maybe use @@templateid in your query predicate to filter down to only the type of items your rendering can handle?
Sent from my iPhone
On Jun 5, 2015, at 1:31 PM, rahm0277 [email protected] wrote:
There are challenges with this - you can theoretically build a datasource that can return different types of models/items. Is there a way to restrict the type of items that can returned in a datasource query?
— Reply to this email directly or view it on GitHub.
Yeah, I guess I can for a specific implementation. But if it needs to be in a generic GetModel pipeline, how would you restrict it? I don't know how I particularly feel about the datasource query field - I really wish they had made it a separate (new) field, and we could restrict it that way. Its a matter of either letting the user choose 1 item, or have them construct a query. If we don't let them construct a query, this is solved. But if we do, I assume you cannot restrict in the generic GetModel - it will need to get filtered in the rendering itself....