Created
January 27, 2013 16:22
-
-
Save jonleighton/4649076 to your computer and use it in GitHub Desktop.
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
| require "active_record" | |
| require "logger" | |
| puts ActiveRecord::VERSION::STRING | |
| $rails4 = ActiveRecord::VERSION::MAJOR > 3 | |
| ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:' | |
| ActiveRecord::Schema.define do | |
| create_table :people | |
| create_table :accesses | |
| create_table :projects | |
| end | |
| class Person < ActiveRecord::Base | |
| has_many :accesses | |
| if $rails4 | |
| has_many :projects, -> { where foo: 'a' }, through: :accesses | |
| else | |
| has_many :projects, conditions: { foo: 'a' }, through: :accesses | |
| end | |
| end | |
| class Access < ActiveRecord::Base | |
| belongs_to :person | |
| if $rails4 | |
| belongs_to :project, -> { where foo: 'b' } | |
| else | |
| belongs_to :project, conditions: { foo: 'b' } | |
| end | |
| end | |
| class Project < ActiveRecord::Base | |
| default_scope -> { where foo: 'c' } | |
| end | |
| person = Person.create | |
| puts person.projects.to_sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment