I have a backbone application with the following architecture:
A PageGroupCollection
is a collection of PageGroupModel
s.
A PageGroupModel
has a PageCollection
as one of it's attributes.
A PageCollection
is a collection of PageModel
s
PageGroupModel
has a permalink
attribute
PageModel
has a permalink
attribute.
I need a function within PageModel
that returns a permalink
that includes both the permalink
of PageModel
thats PageCollection
attribute contains PageGroupModel
and also its own permalink
attribute.
Something like the following:
getFullPermalink: function () {
var parentPermanlink = this.owningCollection.modelCollectionIsAnAttributeOf.get('permalink');
return parentPermalink + "/" + this.get('permalink');
}
Update: Worked by adding the following:
var pageGroup = pageGroupCollection.findWhere({ 'pageCollection': this.collection });
var pageGroupPermalink = pageGroup.get('permalink');
return pageGroupPermalink + "/" + this.get('permalink');