This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Event < CouchRest::Model::Base | |
use_database DB | |
property :event_type, :type => String | |
property :actioner_id, :type => String | |
property :event_date, :type => String | |
property :event_parent, :type => String | |
property :event_hierarchy, :type => [String], :default => [] | |
property :old_state | |
property :new_state |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var asy = require('async'), | |
mc = require('mc'), | |
f = require('fermata'); | |
var DB = 'test'; | |
var client = new mc.Client(), | |
source = f.json("http://localhost:5984")(DB); | |
var page = {limit:5}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Car < ApplicationRecord | |
belongs_to :user | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user = User.create | |
5.times do |i| | |
Review.create(author: user) | |
Car.create(user: user) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irb(main)> user = User.first | |
User Load (1.6ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT ? [["LIMIT", 1]] | |
=> #<User id: 1, created_at: "2017-07-13 18:28:46", updated_at: "2017-07-13 18:28:46"> | |
irb(main)> user.reviews.first.author.object_id == user.object_id | |
Review Load (2.7ms) SELECT "reviews".* FROM "reviews" WHERE "reviews"."author_id" = ? ORDER BY "reviews"."id" ASC LIMIT ? [["author_id", 1], ["LIMIT", 1]] | |
User Load (6.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]] | |
=> false | |
irb(main)> user.cars.first.user.object_id == user.object_id | |
Car Load (1.7ms) SELECT "cars".* FROM "cars" WHERE "cars"."user_id" = ? ORDER BY "cars"."id" ASC LIMIT ? [["user_id", 1], ["LIMIT", 1]] | |
=> true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ApplicationRecord | |
has_many :reviews, inverse_of: 'author', foreign_key: 'author_id' | |
has_many :cars | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irb(main)> user = User.first | |
User Load (2.9ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT ? [["LIMIT", 1]] | |
=> #<User id: 1, created_at: "2017-07-13 18:28:46", updated_at: "2017-07-13 18:28:46"> | |
irb(main)> user.reviews.first.author.object_id == user.object_id | |
CarReview Load (1.4ms) SELECT "reviews".* FROM "reviews" WHERE "reviews"."author_id" = ? ORDER BY "reviews"."id" ASC LIMIT ? [["author_id", 1], ["LIMIT", 1]] | |
=> true | |
irb(main)> user.cars.first.user.object_id == user.object_id | |
Car Load (1.7ms) SELECT "cars".* FROM "cars" WHERE "cars"."user_id" = ? ORDER BY "cars"."id" ASC LIMIT ? [["user_id", 1], ["LIMIT", 1]] | |
=> true |