Skip to content

Instantly share code, notes, and snippets.

@whito
whito / sequelize-include.js
Created November 29, 2012 16:30
Sequelize associated data many-many
// Simple example where you have a many-many relationship with Categories and Posts
// in sequelizejs and want to send the associated data as part of the response
Category.findAll({include: ['posts'] })
.success(function(categories) {
var results = categories.map(function(category) {
var temp = mapAttributes(category);
var p_results = category.posts.map(function(post){
@whito
whito / schema.js
Created September 6, 2012 14:55
Custom Schema
customSchema(function () {
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');
var Schema = mongoose.Schema, ObjectId = Schema.ObjectId;
//-----------------------------
var UserSchema = new Schema({
email: { type: String, required: true },
@whito
whito / login_layout.ejs
Created September 4, 2012 20:32
Routing Problem in RailwayJS
$ rw routes
users GET /users.:format? users#index
users POST /users.:format? users#create
new_user GET /users/new.:format? users#new
edit_user GET /users/:id/edit.:format? users#edit
user DELETE /users/:id.:format? users#destroy
user PUT /users/:id.:format? users#update
user GET /users/:id.:format? users#show
login GET /login users#login