Created
May 10, 2013 12:15
-
-
Save jonleighton/5554056 to your computer and use it in GitHub Desktop.
This file contains 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
gem "rails", "~> 3.2.0" | |
require "active_record" | |
require "logger" | |
ActiveRecord::Base.establish_connection( | |
adapter: "sqlite3", | |
database: ":memory:" | |
) | |
puts ActiveRecord::VERSION::STRING | |
ActiveRecord::Schema.define do | |
create_table :manufacturers | |
create_table :products do |t| | |
t.integer :manufacturer_id | |
t.string :name | |
end | |
end | |
class Manufacturer < ActiveRecord::Base | |
has_many :products, :inverse_of => :manufacturer | |
end | |
class Product < ActiveRecord::Base | |
belongs_to :manufacturer, :inverse_of => :products | |
def self.by_name | |
order(:name) | |
end | |
end | |
m = Manufacturer.create | |
m.products.create | |
ActiveRecord::Base.logger = Logger.new(STDERR) | |
Manufacturer.first.products.first.manufacturer | |
puts "--" | |
products = Manufacturer.first.products | |
p products.method(:first).source_location | |
p products.method(:where).source_location | |
products.where("1=1").first.manufacturer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment