Skip to content

Instantly share code, notes, and snippets.

Code:

    new Account({
      accountNumber: 123123
    }).fetchAll({
      withRelated: 'customer'
    }).then(function(accounts) {
      // accounts has all the elements
    });
var Customer = Bookshelf.Model.extend({
    tableName : 'customers',
    accounts  : function() {
        return this.hasMany(Account, 'customerId');
    }
});

var Account = Bookshelf.Model.extend({
 tableName : 'accounts',
@srushti
srushti / keybase.md
Last active August 29, 2015 13:57
keybase.md

Keybase proof

I hereby claim:

  • I am srushti on github.
  • I am srushti (https://keybase.io/srushti) on keybase.
  • I have a public key whose fingerprint is 55A3 C224 F84A 2DAB 7564 806D 208D 48DD A080 F1D4

To claim this, I am signing this object:

@srushti
srushti / git_shots_hook.rb
Last active December 31, 2015 17:28
Git hooks
#!/usr/bin/ruby
#-*-ruby-*-
# A script to run takes git shots on every commit. Can be run on
# the current dir, called from a git callback, or install itself as a
# git post-commit callback.
HOOKS = %w{post-commit}
HOOKS_DIR = '.git/hooks'
def ensure_git_repo
class PhysicalStorageVolume
OS_VERSION = RbConfig::CONFIG['host_os']
def initialize(path)
@path = path
@path_exists = File.exists?(path)
end
def self.error_raising_method(name)
define_method(name) do |*args|
@srushti
srushti / gist:2651900
Created May 10, 2012 08:33
Vim commands to convert a Test::Unit/Shoulda to RSpec
%s/def test_\(.*\)/it "\1" do
%s/ should / it /
%s/setup do/before(:each) do/
%s/def setup/before(:each) do/
%s/assert_true \(.*\)/\1.should be_true/
%s/assert \(.*\)/\1.should be_true/
%s/assert_false \(.*\)/\1.should be_false/
%s/assert_equal(\(.*\),\(.*\))/\2.should == \1/
%s/assert_equal \(.*\),\(.*\)/\2.should == \1/
%s/assert_nil \(.*\)/\1.should be_nil/
@srushti
srushti / explanation
Created March 12, 2012 13:37
git submodule update --init --recursive
1 had submodule 2
2 had submodule 3
3 had submodule 4