Unitech / angular-bridge

Link models easily via a REST interface between Mongoose/Node-Express/Angular.js
208 stars 22 forks source link

Nested resouces #8

Open simax opened 11 years ago

simax commented 11 years ago

Can we see an example using nested resources, I can't seem to figure out how that would work. I have a mongoose Schema like so:

var mongoose = require('mongoose');

module.exports = function Schemas() {
    this.schema = mongoose.Schema;
    this.EmployeeSchema = new this.schema({
        'firstname': {
            type: String,
            required: true,
            trim: true
        },
        'lastname': {
            type: String,
            required: true,
            trim: true
        },
        'email': {
            type: String,
            required: true,
            trim: true,
            index: true,
            validate: /\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b/
        },
        'departmentId': {
            type: this.schema.ObjectId,
            trim: true,
            required: true
        },
        'enddate': {
            type: String,
            trim: true
        },
        'active': {
            type: Boolean,
            "default": true
        }
    });
    this.EmployeeSchemaModel = mongoose.model('employees', this.EmployeeSchema);

    this.DepartmentSchema = new this.schema({
        'name': {
            type: String,
            required: true,
            trim: true,
            index: {
                unique: true
            }
        },
        'employees': [this.EmployeeSchema]
    });
    this.DepartmentSchemaModel = mongoose.model('departments', this.DepartmentSchema);

    mongoose.connect('mongodb://localhost:8120/staff');
};

So I have Employee documents nested within Departments. How do I configure angular-bridge to give me URL's like:

/departments/{some department id}/employees/{some employee id}

Unitech commented 11 years ago

For now anglar-bridge doesn't handle nested resources, but it's a very interesting feature. Feel free to contribute !

Thanks

simax commented 11 years ago

Ok, thanks for replying. Just wanted to make sure I wasn't missing anything.

dylan-baskind commented 10 years ago

+1 - My Express knowledge isn't up to the task at the moment, but nested resources would be excellent!