repo stringlengths 5 92 | file_url stringlengths 80 287 | file_path stringlengths 5 197 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:37:27 2026-01-04 17:58:21 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/order.rb | activerecord/test/models/order.rb | # frozen_string_literal: true
class Order < ActiveRecord::Base
belongs_to :billing, class_name: "Customer", foreign_key: "billing_customer_id"
belongs_to :shipping, class_name: "Customer", foreign_key: "shipping_customer_id"
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/clothing_item.rb | activerecord/test/models/clothing_item.rb | # frozen_string_literal: true
class ClothingItem < ActiveRecord::Base
query_constraints :clothing_type, :color
end
class ClothingItem::Used < ClothingItem
end
class ClothingItem::Sized < ClothingItem
query_constraints :clothing_type, :color, :size
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/default.rb | activerecord/test/models/default.rb | # frozen_string_literal: true
class Default < ActiveRecord::Base
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/uuid_comment.rb | activerecord/test/models/uuid_comment.rb | # frozen_string_literal: true
class UuidComment < ActiveRecord::Base
has_one :uuid_entry, as: :entryable
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/dl_keyed_has_one.rb | activerecord/test/models/dl_keyed_has_one.rb | # frozen_string_literal: true
class DlKeyedHasOne < ActiveRecord::Base
self.primary_key = "has_one_key"
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/wheel.rb | activerecord/test/models/wheel.rb | # frozen_string_literal: true
class Wheel < ActiveRecord::Base
belongs_to :wheelable, polymorphic: true, counter_cache: true, touch: :wheels_owned_at
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/contract.rb | activerecord/test/models/contract.rb | # frozen_string_literal: true
class Contract < ActiveRecord::Base
belongs_to :company
belongs_to :developer, primary_key: :id
belongs_to :firm, foreign_key: "company_id"
attribute :metadata, :json
before_save :hi, :update_metadata
after_save :bye
attr_accessor :hi_count, :bye_count
def hi
@hi_c... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/treasure.rb | activerecord/test/models/treasure.rb | # frozen_string_literal: true
class Treasure < ActiveRecord::Base
has_and_belongs_to_many :parrots
belongs_to :looter, polymorphic: true
# No counter_cache option given
belongs_to :ship
has_many :price_estimates, as: :estimate_of, autosave: true
has_and_belongs_to_many :rich_people, join_table: "peoples_t... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/membership.rb | activerecord/test/models/membership.rb | # frozen_string_literal: true
class Membership < ActiveRecord::Base
enum :type, %i(Membership CurrentMembership SuperMembership SelectedMembership TenantMembership)
belongs_to :member
belongs_to :club
has_one :sponsor, through: :club
belongs_to :simple_member, foreign_key: "member_id"
end
class CurrentMemb... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/book_identifier.rb | activerecord/test/models/book_identifier.rb | # frozen_string_literal: true
class BookIdentifier < ActiveRecord::Base
belongs_to :book
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/tuning_peg.rb | activerecord/test/models/tuning_peg.rb | # frozen_string_literal: true
class TuningPeg < ActiveRecord::Base
belongs_to :guitar
validates_numericality_of :pitch
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/book_destroy_async.rb | activerecord/test/models/book_destroy_async.rb | # frozen_string_literal: true
class BookDestroyAsync < ActiveRecord::Base
self.table_name = "books"
has_many :taggings, as: :taggable, class_name: "Tagging"
has_many :tags, through: :taggings, dependent: :destroy_async
has_many :essays, dependent: :destroy_async, class_name: "EssayDestroyAsync", foreign_key: ... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/member.rb | activerecord/test/models/member.rb | # frozen_string_literal: true
class Member < ActiveRecord::Base
has_one :current_membership
has_one :selected_membership
has_one :membership
has_one :club, through: :current_membership
has_one :club_without_joins, through: :current_membership, source: :club, disable_joins: true
has_one :selected_club, thro... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/mouse.rb | activerecord/test/models/mouse.rb | # frozen_string_literal: true
class Mouse < ActiveRecord::Base
has_many :squeaks, autosave: true
validates :name, presence: true
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/frog.rb | activerecord/test/models/frog.rb | # frozen_string_literal: true
class Frog < ActiveRecord::Base
after_save do
with_lock do
end
end
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/comment_overlapping_counter_cache.rb | activerecord/test/models/comment_overlapping_counter_cache.rb | # frozen_string_literal: true
class CommentOverlappingCounterCache < ActiveRecord::Base
belongs_to :user_comments_count, counter_cache: :comments_count
belongs_to :post_comments_count, class_name: "PostCommentsCount"
belongs_to :commentable, polymorphic: true, counter_cache: :comments_count
end
class UserCommen... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/tree.rb | activerecord/test/models/tree.rb | # frozen_string_literal: true
class Tree < ActiveRecord::Base
has_many :nodes, dependent: :destroy
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/customer.rb | activerecord/test/models/customer.rb | # frozen_string_literal: true
class Customer < ActiveRecord::Base
cattr_accessor :gps_conversion_was_run
composed_of :address, mapping: [ %w(address_street street), %w(address_city city), %w(address_country country) ], allow_nil: true
composed_of :address_hash_mapping, class_name: "Address",
mappi... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/bulb.rb | activerecord/test/models/bulb.rb | # frozen_string_literal: true
class Bulb < ActiveRecord::Base
default_scope { where(name: "defaulty") }
belongs_to :car, touch: true, counter_cache: { active: false }
scope :awesome, -> { where(frickinawesome: true) }
attr_reader :scope_after_initialize, :attributes_after_initialize, :count_after_create
af... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/squeak.rb | activerecord/test/models/squeak.rb | # frozen_string_literal: true
class Squeak < ActiveRecord::Base
belongs_to :mouse
accepts_nested_attributes_for :mouse
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/lesson.rb | activerecord/test/models/lesson.rb | # frozen_string_literal: true
class LessonError < Exception
end
class Lesson < ActiveRecord::Base
has_and_belongs_to_many :students
before_destroy :ensure_no_students
def ensure_no_students
raise LessonError unless students.empty?
end
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/dl_keyed_has_many.rb | activerecord/test/models/dl_keyed_has_many.rb | # frozen_string_literal: true
class DlKeyedHasMany < ActiveRecord::Base
self.primary_key = "many_key"
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/dashboard.rb | activerecord/test/models/dashboard.rb | # frozen_string_literal: true
class Dashboard < ActiveRecord::Base
self.primary_key = :dashboard_id
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/topic.rb | activerecord/test/models/topic.rb | # frozen_string_literal: true
class Topic < ActiveRecord::Base
scope :base, -> { all }
scope :written_before, lambda { |time|
if time
where "written_on < ?", time
end
}
scope :approved, -> { where(approved: true) }
scope :rejected, -> { where(approved: false) }
scope :true, -> { where(approv... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/ship_part.rb | activerecord/test/models/ship_part.rb | # frozen_string_literal: true
class ShipPart < ActiveRecord::Base
belongs_to :ship
has_many :trinkets, class_name: "Treasure", as: :looter
accepts_nested_attributes_for :trinkets, allow_destroy: true
accepts_nested_attributes_for :ship
validates_presence_of :name
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/chef.rb | activerecord/test/models/chef.rb | # frozen_string_literal: true
class Chef < ActiveRecord::Base
belongs_to :employable, polymorphic: true
has_many :recipes
end
class ChefList < Chef
belongs_to :employable_list, polymorphic: true
end
class ChefWithPolymorphicInverseOf < Chef
attr_reader :before_validation_callbacks_counter
attr_reader :befo... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/traffic_light.rb | activerecord/test/models/traffic_light.rb | # frozen_string_literal: true
class TrafficLight < ActiveRecord::Base
serialize :state, type: Array
serialize :long_state, type: Array
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/treaty.rb | activerecord/test/models/treaty.rb | # frozen_string_literal: true
class Treaty < ActiveRecord::Base
has_and_belongs_to_many :countries
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/carrier.rb | activerecord/test/models/carrier.rb | # frozen_string_literal: true
class Carrier < ActiveRecord::Base
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/item.rb | activerecord/test/models/item.rb | # frozen_string_literal: true
class AbstractItem < ActiveRecord::Base
self.abstract_class = true
has_one :tagging, as: :taggable
end
class Item < AbstractItem
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/account.rb | activerecord/test/models/account.rb | # frozen_string_literal: true
class Account < ActiveRecord::Base
belongs_to :firm, class_name: "Company"
belongs_to :unautosaved_firm, foreign_key: "firm_id", class_name: "Firm", autosave: false
alias_attribute :available_credit, :credit_limit
def self.destroyed_account_ids
@destroyed_account_ids ||= Has... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/minivan.rb | activerecord/test/models/minivan.rb | # frozen_string_literal: true
class Minivan < ActiveRecord::Base
self.primary_key = :minivan_id
belongs_to :speedometer
has_one :dashboard, through: :speedometer
attr_readonly :color
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/family.rb | activerecord/test/models/family.rb | # frozen_string_literal: true
class Family < ActiveRecord::Base
has_many :family_trees, -> { where(token: nil) }
has_many :members, through: :family_trees
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/computer.rb | activerecord/test/models/computer.rb | # frozen_string_literal: true
class Computer < ActiveRecord::Base
belongs_to :developer, foreign_key: "developer"
has_one :firm, through: :developer
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/hardback.rb | activerecord/test/models/hardback.rb | # frozen_string_literal: true
class Hardback < ActiveRecord::Base
end
class BestHardback < Hardback
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/invokes_an_undefined_method.rb | activerecord/test/models/invokes_an_undefined_method.rb | # frozen_string_literal: true
class InvokesAnUndefinedMethod
this_method_is_undefined
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/mixed_case_monkey.rb | activerecord/test/models/mixed_case_monkey.rb | # frozen_string_literal: true
class MixedCaseMonkey < ActiveRecord::Base
belongs_to :human
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/personal_legacy_thing.rb | activerecord/test/models/personal_legacy_thing.rb | # frozen_string_literal: true
class PersonalLegacyThing < ActiveRecord::Base
self.locking_column = :version
belongs_to :person, counter_cache: true
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/book_encrypted.rb | activerecord/test/models/book_encrypted.rb | # frozen_string_literal: true
class UnencryptedBook < ActiveRecord::Base
self.table_name = "encrypted_books"
end
class EncryptedBook < ActiveRecord::Base
self.table_name = "encrypted_books"
encrypts :name, deterministic: true
end
class EncryptedBookWithUniquenessValidation < ActiveRecord::Base
self.table_na... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/customer_carrier.rb | activerecord/test/models/customer_carrier.rb | # frozen_string_literal: true
class CustomerCarrier < ActiveRecord::Base
cattr_accessor :current_customer
belongs_to :customer
belongs_to :carrier
default_scope -> {
if current_customer
where(customer: current_customer)
else
all
end
}
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/translation.rb | activerecord/test/models/translation.rb | # frozen_string_literal: true
class Translation < ActiveRecord::Base
belongs_to :attachment, optional: true
validates :locale, presence: true
validates :key, presence: true
validates :value, presence: true
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/section.rb | activerecord/test/models/section.rb | # frozen_string_literal: true
class Section < ActiveRecord::Base
belongs_to :session, inverse_of: :sections, autosave: true
belongs_to :seminar, inverse_of: :sections, autosave: true
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/editorship.rb | activerecord/test/models/editorship.rb | # frozen_string_literal: true
class Editorship < ActiveRecord::Base
belongs_to :publication
belongs_to :editor
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/college.rb | activerecord/test/models/college.rb | # frozen_string_literal: true
require "models/arunit2_model"
require "active_support/core_ext/object/with_options"
class College < ARUnit2Model
has_many :courses
with_options dependent: :destroy do |assoc|
assoc.has_many :students, -> { where(active: true) }
end
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/drink_designer.rb | activerecord/test/models/drink_designer.rb | # frozen_string_literal: true
class DrinkDesigner < ActiveRecord::Base
has_one :chef, as: :employable
accepts_nested_attributes_for :chef
end
class DrinkDesignerWithPolymorphicDependentNullifyChef < ActiveRecord::Base
self.table_name = "drink_designers"
has_one :chef, as: :employable, dependent: :nullify
end... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/member_type.rb | activerecord/test/models/member_type.rb | # frozen_string_literal: true
class MemberType < ActiveRecord::Base
has_many :members
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/uuid_item.rb | activerecord/test/models/uuid_item.rb | # frozen_string_literal: true
class UuidItem < ActiveRecord::Base
end
class UuidValidatingItem < UuidItem
validates_uniqueness_of :uuid
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/pet.rb | activerecord/test/models/pet.rb | # frozen_string_literal: true
class Pet < ActiveRecord::Base
attr_accessor :current_user
self.primary_key = :pet_id
belongs_to :owner, touch: true
has_many :toys
has_many :pet_treasures
has_many :treasures, through: :pet_treasures
has_many :persons, through: :treasures, source: :looter, source_type: "Pe... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/human.rb | activerecord/test/models/human.rb | # frozen_string_literal: true
class Human < ActiveRecord::Base
self.table_name = "humans"
has_one :face, inverse_of: :human
has_one :autosave_face, class_name: "Face", autosave: true, inverse_of: :autosave_human
has_one :polymorphic_face, class_name: "Face", as: :polymorphic_human, inverse_of: :polymorphic_hu... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/recipient.rb | activerecord/test/models/recipient.rb | # frozen_string_literal: true
class Recipient < ActiveRecord::Base
belongs_to :message, touch: true
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/node.rb | activerecord/test/models/node.rb | # frozen_string_literal: true
class Node < ActiveRecord::Base
belongs_to :tree, touch: true
belongs_to :parent, class_name: "Node", touch: true, optional: true
has_many :children, class_name: "Node", foreign_key: :parent_id, dependent: :destroy
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/professor.rb | activerecord/test/models/professor.rb | # frozen_string_literal: true
require "models/arunit2_model"
class Professor < ARUnit2Model
has_and_belongs_to_many :courses
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/vegetables.rb | activerecord/test/models/vegetables.rb | # frozen_string_literal: true
class Vegetable < ActiveRecord::Base
validates_presence_of :name
def self.inheritance_column
"custom_type"
end
end
class Cucumber < Vegetable
end
class Cabbage < Vegetable
end
class GreenCabbage < Cabbage
end
class KingCole < GreenCabbage
end
class RedCabbage < Cabbage
b... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/publisher.rb | activerecord/test/models/publisher.rb | # frozen_string_literal: true
module Publisher
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/citation.rb | activerecord/test/models/citation.rb | # frozen_string_literal: true
class Citation < ActiveRecord::Base
belongs_to :book, foreign_key: :book1_id, inverse_of: :citations, touch: true
belongs_to :reference_of, class_name: "Book", foreign_key: :book2_id
has_many :citations
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/dl_keyed_has_many_through.rb | activerecord/test/models/dl_keyed_has_many_through.rb | # frozen_string_literal: true
class DlKeyedHasManyThrough < ActiveRecord::Base
self.primary_key = :through_key
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/pet_treasure.rb | activerecord/test/models/pet_treasure.rb | # frozen_string_literal: true
class PetTreasure < ActiveRecord::Base
self.table_name = "pets_treasures"
belongs_to :pet
belongs_to :treasure
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/column_name.rb | activerecord/test/models/column_name.rb | # frozen_string_literal: true
class ColumnName < ActiveRecord::Base
self.table_name = "colnametests"
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/destroy_async_parent.rb | activerecord/test/models/destroy_async_parent.rb | # frozen_string_literal: true
class DestroyAsyncParent < ActiveRecord::Base
self.primary_key = "parent_id"
has_one :dl_keyed_has_one, dependent: :destroy_async,
foreign_key: :destroy_async_parent_id, primary_key: :parent_id
has_many :dl_keyed_has_many, dependent: :destroy_async,
foreign_key: :man... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/tire.rb | activerecord/test/models/tire.rb | # frozen_string_literal: true
class Tire < ActiveRecord::Base
belongs_to :car, counter_cache: { active: true, column: :custom_tires_count }
def self.custom_find(id)
find(id)
end
def self.custom_find_by(*args)
find_by(*args)
end
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/entrant.rb | activerecord/test/models/entrant.rb | # frozen_string_literal: true
class Entrant < ActiveRecord::Base
belongs_to :course
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/ship.rb | activerecord/test/models/ship.rb | # frozen_string_literal: true
class Ship < ActiveRecord::Base
self.record_timestamps = false
belongs_to :pirate
belongs_to :update_only_pirate, class_name: "Pirate"
belongs_to :developer, dependent: :destroy
has_many :parts, class_name: "ShipPart"
has_many :treasures
accepts_nested_attributes_for :part... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/boolean.rb | activerecord/test/models/boolean.rb | # frozen_string_literal: true
class Boolean < ActiveRecord::Base
def has_fun
super
end
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/country.rb | activerecord/test/models/country.rb | # frozen_string_literal: true
class Country < ActiveRecord::Base
has_and_belongs_to_many :treaties
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/room.rb | activerecord/test/models/room.rb | # frozen_string_literal: true
class Room < ActiveRecord::Base
belongs_to :user
belongs_to :owner, class_name: "User"
belongs_to :landlord, class_name: "User", dependent: :destroy, inverse_of: :let_room
belongs_to :tenant, class_name: "User", dependent: :destroy, inverse_of: :rented_room
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/owner.rb | activerecord/test/models/owner.rb | # frozen_string_literal: true
class Owner < ActiveRecord::Base
self.primary_key = :owner_id
has_many :pets, -> { order "pets.name desc" }
has_many :toys, through: :pets
has_many :persons, through: :pets
belongs_to :last_pet, class_name: "Pet"
scope :including_last_pet, -> {
select('
owners.*, (
... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/reader.rb | activerecord/test/models/reader.rb | # frozen_string_literal: true
class Reader < ActiveRecord::Base
belongs_to :post
belongs_to :person, inverse_of: :readers
belongs_to :single_person, class_name: "Person", foreign_key: :person_id, inverse_of: :reader
belongs_to :first_post, -> { where(id: [2, 3]) }
end
class SecureReader < ActiveRecord::Base
... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/cart.rb | activerecord/test/models/cart.rb | # frozen_string_literal: true
class Cart < ActiveRecord::Base
self.primary_key = :id
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/category.rb | activerecord/test/models/category.rb | # frozen_string_literal: true
class Category < ActiveRecord::Base
has_and_belongs_to_many :posts
has_and_belongs_to_many :special_posts, class_name: "Post"
has_and_belongs_to_many :other_posts, class_name: "Post"
has_and_belongs_to_many :posts_with_authors_sorted_by_author_id, -> { includes(:authors).order("au... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/enrollment.rb | activerecord/test/models/enrollment.rb | # frozen_string_literal: true
class Enrollment < ActiveRecord::Base
belongs_to :program
belongs_to :member, class_name: "SimpleMember"
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/publication.rb | activerecord/test/models/publication.rb | # frozen_string_literal: true
class Publication < ActiveRecord::Base
belongs_to :editor_in_chief, class_name: "Editor", inverse_of: :publication, optional: true
has_many :editorships
has_many :editors, through: :editorships
after_initialize do
self.editor_in_chief = build_editor_in_chief(name: "John Doe")... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/program.rb | activerecord/test/models/program.rb | # frozen_string_literal: true
class Program < ActiveRecord::Base
has_many :enrollments
has_many :members, through: :enrollments, class_name: "SimpleMember"
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/molecule.rb | activerecord/test/models/molecule.rb | # frozen_string_literal: true
class Molecule < ActiveRecord::Base
belongs_to :liquid
has_many :electrons
accepts_nested_attributes_for :electrons
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/categorization.rb | activerecord/test/models/categorization.rb | # frozen_string_literal: true
class Categorization < ActiveRecord::Base
belongs_to :post
belongs_to :category, counter_cache: true
belongs_to :named_category, class_name: "Category", foreign_key: :named_category_name, primary_key: :name
belongs_to :author
has_many :post_taggings, through: :author, source: :... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/essay.rb | activerecord/test/models/essay.rb | # frozen_string_literal: true
class Essay < ActiveRecord::Base
belongs_to :author, primary_key: :name
belongs_to :writer, primary_key: :name, polymorphic: true
belongs_to :category, primary_key: :name
has_one :owner, primary_key: :name
end
class EssaySpecial < Essay
end
class TypedEssay < Essay
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/destroy_async_parent_soft_delete.rb | activerecord/test/models/destroy_async_parent_soft_delete.rb | # frozen_string_literal: true
class DestroyAsyncParentSoftDelete < ActiveRecord::Base
has_many :taggings, as: :taggable, class_name: "Tagging"
has_many :tags, through: :taggings,
dependent: :destroy_async,
ensuring_owner_was: :deleted?
has_one :dl_keyed_has_one, dependent: :destroy_async,
ensuring_o... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/post_with_prefetched_pk.rb | activerecord/test/models/post_with_prefetched_pk.rb | # frozen_string_literal: true
class PostWithPrefetchedPk < ActiveRecord::Base
self.table_name = "posts"
class << self
def prefetch_primary_key?
true
end
def next_sequence_value
123456
end
end
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/program_offering.rb | activerecord/test/models/program_offering.rb | # frozen_string_literal: true
class ProgramOffering < ActiveRecord::Base
belongs_to :club
belongs_to :program
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/parrot.rb | activerecord/test/models/parrot.rb | # frozen_string_literal: true
class Parrot < ActiveRecord::Base
self.inheritance_column = :parrot_sti_class
has_and_belongs_to_many :pirates
has_and_belongs_to_many :treasures
has_many :loots, as: :looter, class_name: "Treasure"
alias_attribute :title, :name
validates_presence_of :name
attribute :canc... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/line_item.rb | activerecord/test/models/line_item.rb | # frozen_string_literal: true
class LineItem < ActiveRecord::Base
belongs_to :invoice, touch: true
has_many :discount_applications, class_name: "LineItemDiscountApplication"
end
class LineItemDiscountApplication < ActiveRecord::Base
belongs_to :line_item
belongs_to :discount
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/string_key_object.rb | activerecord/test/models/string_key_object.rb | # frozen_string_literal: true
class StringKeyObject < ActiveRecord::Base
self.primary_key = :id
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/other_dog.rb | activerecord/test/models/other_dog.rb | # frozen_string_literal: true
require "models/arunit2_model"
class OtherDog < ARUnit2Model
self.table_name = "dogs"
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/movie.rb | activerecord/test/models/movie.rb | # frozen_string_literal: true
class Movie < ActiveRecord::Base
self.primary_key = "movieid"
validates_presence_of :name
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/discount.rb | activerecord/test/models/discount.rb | # frozen_string_literal: true
class Discount < ActiveRecord::Base
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/author.rb | activerecord/test/models/author.rb | # frozen_string_literal: true
class Author < ActiveRecord::Base
has_many :posts
has_many :serialized_posts
has_one :post
has_many :very_special_comments, through: :posts
has_many :posts_with_comments, -> { includes(:comments) }, class_name: "Post"
has_many :popular_grouped_posts, -> { includes(:comments).g... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/auto_id.rb | activerecord/test/models/auto_id.rb | # frozen_string_literal: true
class AutoId < ActiveRecord::Base
self.table_name = "auto_id_tests"
self.primary_key = "auto_id"
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/raises_argument_error.rb | activerecord/test/models/raises_argument_error.rb | # frozen_string_literal: true
class RaisesArgumentError
raise ArgumentError
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/uuid_parent.rb | activerecord/test/models/uuid_parent.rb | # frozen_string_literal: true
class UuidParent < ActiveRecord::Base
has_many :uuid_children
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/comment.rb | activerecord/test/models/comment.rb | # frozen_string_literal: true
# `counter_cache` requires association class before `attr_readonly`.
class Post < ActiveRecord::Base; end
class Comment < ActiveRecord::Base
scope :limit_by, lambda { |l| limit(l) }
scope :containing_the_letter_e, -> { where("comments.body LIKE '%e%'") }
scope :not_again, -> { wher... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/matey.rb | activerecord/test/models/matey.rb | # frozen_string_literal: true
class Matey < ActiveRecord::Base
belongs_to :pirate
belongs_to :target, class_name: "Pirate"
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/traffic_light_encrypted.rb | activerecord/test/models/traffic_light_encrypted.rb | # frozen_string_literal: true
require "models/traffic_light"
class EncryptedTrafficLight < TrafficLight
encrypts :state
end
class EncryptedFirstTrafficLight < ActiveRecord::Base
self.table_name = "traffic_lights"
encrypts :state
serialize :state, type: Array
serialize :long_state, type: Array
end
class ... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/dog_lover.rb | activerecord/test/models/dog_lover.rb | # frozen_string_literal: true
class DogLover < ActiveRecord::Base
has_many :trained_dogs, class_name: "Dog", foreign_key: :trainer_id, dependent: :destroy
has_many :bred_dogs, class_name: "Dog", foreign_key: :breeder_id
has_many :dogs
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/attachment.rb | activerecord/test/models/attachment.rb | # frozen_string_literal: true
class Attachment < ActiveRecord::Base
belongs_to :record, polymorphic: true
has_one :translation
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/face.rb | activerecord/test/models/face.rb | # frozen_string_literal: true
class Face < ActiveRecord::Base
belongs_to :human, inverse_of: :face
belongs_to :autosave_human, class_name: "Human", foreign_key: :human_id, inverse_of: :autosave_face
belongs_to :super_human, polymorphic: true
belongs_to :polymorphic_human, polymorphic: true, inverse_of: :polymo... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/doubloon.rb | activerecord/test/models/doubloon.rb | # frozen_string_literal: true
class AbstractDoubloon < ActiveRecord::Base
# This has functionality that might be shared by multiple classes.
self.abstract_class = true
belongs_to :pirate
end
class Doubloon < AbstractDoubloon
# This uses an abstract class that defines attributes and associations.
self.tabl... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/legacy_thing.rb | activerecord/test/models/legacy_thing.rb | # frozen_string_literal: true
class LegacyThing < ActiveRecord::Base
self.locking_column = :version
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/message.rb | activerecord/test/models/message.rb | # frozen_string_literal: true
class Message < ActiveRecord::Base
has_one :entry, as: :entryable, touch: true
has_many :recipients
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/liquid.rb | activerecord/test/models/liquid.rb | # frozen_string_literal: true
class Liquid < ActiveRecord::Base
self.table_name = :liquid
has_many :molecules, -> { distinct }
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/department.rb | activerecord/test/models/department.rb | # frozen_string_literal: true
class Department < ActiveRecord::Base
has_many :chefs
belongs_to :hotel
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/test/models/without_table.rb | activerecord/test/models/without_table.rb | # frozen_string_literal: true
class WithoutTable < ActiveRecord::Base
default_scope -> { where(published: true) }
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.