Questions about models and relationships

First of all, I really do like the way you've set up the models, store, and source. It's very well thought out.

In my application I have a Message (like an email) that comes from a Contact. Pretty standard one-to-many relationship. When I'm fetching the list of Messages, I'd like to be able to click the "Contact" in the view, and have the Contact in my Message model to become the source binding for the new view.

I got the binding part down correctly, but I'm struggling a little with the right way to model these things - also the correct way to serve the data up from my restful endpoints.

When I retrieve my messages, I want the contact to be included in the payload - I don't want a lazy fetch where the browser has to make 50 individual requests to hydrate the contact inside the Message object. However, when I include the contact as plain json, the resulting property in the model is not a "Contact" instance, but rather a simple map with the properties in it. I think this may be why some of my child bindings are failing.

I tried having the server lazy fetch the relationship, but could never get the right combination of remoteKey, key, etc. to make it work right. It would fire off an http request, but the request would never be able to figure out the right key to us in the look up.

I'm having issues the other way. If I select a contact record from the server, I'd like to lazy-load the collection of messages - but I can't seem to get anything to "fire" off to go retrieve them from the server. The DataList they are bound to just recognizes the list as being empty.

Here is the latest version of my models (I think I've tried 100 combinations without any luck)

name: "ex.Message",
kind: "enyo.Model",
url: "message",
attributes: {
id: { type: String },
activityDate: { type: String },
followupDate: { type: String },
description: {type: String},
contact: {
remoteKey: "contactId",
relation: enyo.toOne({
// relationKey: "id",
// inverseKey: "contactid",
// inverseKey: "id",
autoFetch: true,
inCommit: false,
isOwner: false,
model: "ex.Contact"
channel: {type: String},
readStatus: {type: Boolean},
photoUrl: {type: String},
subject: {type: String},
body: {type: String}

name: "ex.Contact",
kind: "enyo.Model",
url: "contact",

attributes: {
id: { type: Number },
name: { type: String },
email: {type: String},
photoUrl: {type: String},
coverUrl: {type: String},
messages: {
relation: enyo.toMany({
autoFetch: true,
inCommit: false,
inverseKey: "contact",
relationKey: "id",
model: "ex.Message"

Any help would be greatly appreciated - especially with the remoteKey, relationKey, inverseKey, etc.



  • Suggest you check out the Flyapp . It seems like that's what your looking for. It is a good demo of a repeating data list with an item detail view. I found the code confusing to begin with, though not as confusing as the flickr app. And It seems that auto-bindings and bindFrom are going away and the Flyapp makes significant use of them. But It has a great demonstration of a remote source fetch. And the code looks very interesting and clean.
  • The FlyApp URL is I was just updated to match the pilot6 release.
  • Great to hear that FlyApp has been updated. I found it difficult to use as a reference before because it hadn't been updated.

    That said, the FlyApp doesn't help with my question because it doesn't define any relationships. I'm not having a problem binding data from a controller into my view, or loading a detail view when an item in the list is clicked on. I'm having problem loading data that spans across relationships.

    I know my original post was really long - I'll try to sum the two main issues:

    When you are fetching the "many" side of a one-to-many relationship but you want to also send the "parent" from the server to avoid multiple subsequent requests, how should the data be passed from the server to ensure that the child object's parent is represented as a "Model" object, and not a plain json object?

    (And then essentially the inverse) When you select the "one" side, but you don't want to fetch the collection of children, how do you get enyo to fetch that automatically for you? Right now I'm having to manage the collections separately.

    Thanks again... I'll read more and see if I can produce something more specific.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!