Skip to content

Instantly share code, notes, and snippets.

@welingtonsampaio
Created August 31, 2015 17:00
Show Gist options
  • Save welingtonsampaio/860ca5e1f009ba9c4c65 to your computer and use it in GitHub Desktop.
Save welingtonsampaio/860ca5e1f009ba9c4c65 to your computer and use it in GitHub Desktop.
RABL filter, like Facebook Graph API
class CreateComments < ActiveRecord::Migration
def change
create_table :comments do |t|
t.string :title
t.text :content
t.bollean :active, default: false
t.belongs_to :user
t.timestamps null: false
end
add_index :comments, :user_id
end
end
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.date :birthdate
t.bollean :active, default: false
t.timestamps null: false
end
end
end
[
{
"id": 1,
"name": "Welington Sampaio",
"birthdate": 01-01-1980,
"active": true,
"created_at": 01-08-2015,
"updated_at": 01-08-2015,
"comments": [
{
"id": 1,
"title": "Title 1",
"content": "Lorem ipsum ....",
"created_at": 01-08-2015,
"updated_at": 01-08-2015
}
# 500+ entries
]
},
{
"id": 2,
"name": "Elison Campos",
"birthdate": 01-01-1985,
"active": true,
"created_at": 10-08-2015,
"updated_at": 10-08-2015,
"comments": [
{
"id": 1502,
"title": "Elison Title 1",
"content": "Lorem ipsum ....",
"created_at": 10-08-2015,
"updated_at": 10-08-2015
}
# 30+ entries
]
}
# n+ entries
]
[
{
"id": 1,
"name": "Welington Sampaio",
"birthdate": 01-01-1980,
"comments": [
{
"id": 1,
"title": "Title 1",
"created_at": 01-08-2015
}
# + 9 entries
]
},
{
"id": 2,
"name": "Elison Campos",
"birthdate": 01-01-1985,
"comments": [
{
"id": 1502,
"title": "Elison Title 1",
"created_at": 10-08-2015
}
# + 9 entries
]
}
# n+ entries
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment