jasonhinkle / phreeze

Phreeze Framework for PHP
http://phreeze.com/
GNU Lesser General Public License v2.1
377 stars 166 forks source link

Backbone relational models #50

Open xtrasmal opened 11 years ago

xtrasmal commented 11 years ago

hi there,

So now that I have got the Phreeze Views updating nicely, I want to have my Posts and PostComments to work. After reading a lot about backbone, I found this library and tutorial companion: http://antoviaque.org/docs/tutorials/backbone-relational-tutorial/

I have been following the tutorial on a test build of Phreeze and the api/Posts does not show the relations like in the tutorial.

Can somebody follow the tutorial and see if they get the same results? These are my models:

Comments( the names are still ugly, but that's because I made a quick demo build)

/**
 * TbComments Backbone Model
 */
model.TbCommentsModel = Backbone.RelationalModel.extend({
    urlRoot: 'api/tbcomments',
    idAttribute: 'id',
    id: '',
    postId: '',
    authorId: '',
    date: '',
    content: '',
    defaults: {
        'id': null,
        'postId': '',
        'authorId': '',
        'date': new Date(),
        'content': ''
    }
});

My Posts Model

/**
 * TbPosts Backbone Model
 */
model.TbPostsModel = Backbone.RelationalModel.extend({
    urlRoot: 'api/tbposts',
    idAttribute: 'id',
    id: '',
    authorId: '',
    title: '',
    content: '',
    excerpt: '',
    date: '',
    defaults: {
        'id': null,
        'authorId': '',
        'title': '',
        'content': '',
        'excerpt': '',
        'date': new Date()
    },
    relations: [{
        type: Backbone.HasMany,
        key: 'comments',
        relatedModel: 'model.TbCommentsModel',
        reverseRelation: {
            key: 'post',
            includeInJSON: 'id',
        },
    }]  
});

The application works fine. I can update, delete, edit etc. But the relations aren't shown like in the tutorial. Any suggestions?

jasonhinkle commented 11 years ago

Hmm, to be honest I never even knew that backbone supported relations. That should definitely be a part of the generated model file. I'll have to do some research on that, though.

harinanda commented 11 years ago

please enable backbone-relation ,it will enhance framework capability and can introduce master detail easily.i am trying to learn phreeze.then i will try to enable/implement

jasonhinkle commented 11 years ago

I'd definitely like to implement this. It looks like Backbone.js doesn't natively support relationships so I've been hesitant to integrate something into Phreeze until I felt like it was mature (or at least would continue to be supported as backbone.js is updated). I found another project which is very interesting at https://github.com/PaulUithol/Backbone-relational