2017-07-09 13:41:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2005-04-03 06:52:05 -04:00
|
|
|
class Post < ActiveRecord::Base
|
2013-08-29 14:49:23 -04:00
|
|
|
class CategoryPost < ActiveRecord::Base
|
|
|
|
self.table_name = "categories_posts"
|
|
|
|
belongs_to :category
|
|
|
|
belongs_to :post
|
|
|
|
end
|
|
|
|
|
2010-04-02 12:34:48 -04:00
|
|
|
module NamedExtension
|
|
|
|
def author
|
2016-08-06 12:26:20 -04:00
|
|
|
"lifo"
|
2010-04-02 12:34:48 -04:00
|
|
|
end
|
2017-04-22 03:28:20 -04:00
|
|
|
|
|
|
|
def greeting
|
|
|
|
super + " :)"
|
|
|
|
end
|
2010-04-02 12:34:48 -04:00
|
|
|
end
|
|
|
|
|
2013-01-18 07:30:47 -05:00
|
|
|
module NamedExtension2
|
|
|
|
def greeting
|
2017-05-15 23:10:37 -04:00
|
|
|
"hullo"
|
2013-01-18 07:30:47 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-21 18:18:18 -04:00
|
|
|
scope :containing_the_letter_a, -> { where("body LIKE '%a%'") }
|
2014-06-22 23:42:46 -04:00
|
|
|
scope :titled_with_an_apostrophe, -> { where("title LIKE '%''%'") }
|
2017-09-27 00:25:14 -04:00
|
|
|
scope :ranked_by_comments, -> { order(arel_attribute(:comments_count).desc) }
|
2011-04-08 18:54:54 -04:00
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
scope :limit_by, lambda { |l| limit(l) }
|
2017-06-28 13:11:28 -04:00
|
|
|
scope :locked, -> { lock }
|
2008-06-21 07:41:30 -04:00
|
|
|
|
2013-01-24 04:07:51 -05:00
|
|
|
belongs_to :author
|
2016-08-18 22:17:23 -04:00
|
|
|
belongs_to :readonly_author, -> { readonly }, class_name: "Author", foreign_key: :author_id
|
2005-11-03 04:06:42 -05:00
|
|
|
|
2016-08-06 13:37:57 -04:00
|
|
|
belongs_to :author_with_posts, -> { includes(:posts) }, class_name: "Author", foreign_key: :author_id
|
|
|
|
belongs_to :author_with_address, -> { includes(:author_address) }, class_name: "Author", foreign_key: :author_id
|
2019-02-12 12:06:06 -05:00
|
|
|
belongs_to :author_with_select, -> { select(:id) }, class_name: "Author", foreign_key: :author_id
|
2005-11-06 15:39:34 -05:00
|
|
|
|
2011-11-29 12:14:21 -05:00
|
|
|
def first_comment
|
|
|
|
super.body
|
|
|
|
end
|
2017-09-26 11:29:24 -04:00
|
|
|
has_one :first_comment, -> { order("id ASC") }, class_name: "Comment"
|
|
|
|
has_one :last_comment, -> { order("id desc") }, class_name: "Comment"
|
2008-05-01 19:00:42 -04:00
|
|
|
|
2019-04-26 07:03:03 -04:00
|
|
|
scope :no_comments, -> { left_joins(:comments).where(comments: { id: nil }) }
|
2016-08-16 03:30:11 -04:00
|
|
|
scope :with_special_comments, -> { joins(:comments).where(comments: { type: "SpecialComment" }) }
|
|
|
|
scope :with_very_special_comments, -> { joins(:comments).where(comments: { type: "VerySpecialComment" }) }
|
2016-08-06 13:37:57 -04:00
|
|
|
scope :with_post, ->(post_id) { joins(:comments).where(comments: { post_id: post_id }) }
|
2009-01-24 12:54:10 -05:00
|
|
|
|
2013-01-12 10:22:17 -05:00
|
|
|
scope :with_comments, -> { preload(:comments) }
|
|
|
|
scope :with_tags, -> { preload(:taggings) }
|
|
|
|
|
2014-04-11 19:14:51 -04:00
|
|
|
scope :tagged_with, ->(id) { joins(:taggings).where(taggings: { tag_id: id }) }
|
2014-08-18 17:18:34 -04:00
|
|
|
scope :tagged_with_comment, ->(comment) { joins(:taggings).where(taggings: { comment: comment }) }
|
2014-04-11 19:14:51 -04:00
|
|
|
|
2014-06-22 23:42:46 -04:00
|
|
|
scope :typographically_interesting, -> { containing_the_letter_a.or(titled_with_an_apostrophe) }
|
|
|
|
|
2016-10-28 23:05:58 -04:00
|
|
|
has_many :comments do
|
2005-11-03 04:06:42 -05:00
|
|
|
def find_most_recent
|
2017-09-26 11:29:24 -04:00
|
|
|
order("id DESC").first
|
2005-11-03 04:06:42 -05:00
|
|
|
end
|
2011-06-02 22:58:00 -04:00
|
|
|
|
|
|
|
def newest
|
|
|
|
created.last
|
|
|
|
end
|
2011-12-08 14:58:59 -05:00
|
|
|
|
|
|
|
def the_association
|
|
|
|
proxy_association
|
|
|
|
end
|
2017-03-18 05:17:34 -04:00
|
|
|
|
|
|
|
def with_content(content)
|
|
|
|
self.detect { |comment| comment.body == content }
|
|
|
|
end
|
2005-11-06 14:05:42 -05:00
|
|
|
end
|
2005-11-03 04:06:42 -05:00
|
|
|
|
2013-01-18 07:30:47 -05:00
|
|
|
has_many :comments_with_extend, extend: NamedExtension, class_name: "Comment", foreign_key: "post_id" do
|
|
|
|
def greeting
|
|
|
|
"hello"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
has_many :comments_with_extend_2, extend: [NamedExtension, NamedExtension2], class_name: "Comment", foreign_key: "post_id"
|
|
|
|
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :author_favorites, through: :author
|
2019-03-01 13:19:47 -05:00
|
|
|
has_many :author_favorites_with_scope, through: :author, class_name: "AuthorFavoriteWithScope", source: "author_favorites"
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :author_categorizations, through: :author, source: :categorizations
|
|
|
|
has_many :author_addresses, through: :author
|
2013-10-27 13:39:22 -04:00
|
|
|
has_many :author_address_extra_with_address,
|
|
|
|
through: :author_with_address,
|
|
|
|
source: :author_address_extra
|
2008-10-04 10:42:36 -04:00
|
|
|
|
2005-11-04 14:39:50 -05:00
|
|
|
has_one :very_special_comment
|
2016-08-06 13:37:57 -04:00
|
|
|
has_one :very_special_comment_with_post, -> { includes(:post) }, class_name: "VerySpecialComment"
|
2017-10-11 15:16:57 -04:00
|
|
|
has_one :very_special_comment_with_post_with_joins, -> { joins(:post).order("posts.id") }, class_name: "VerySpecialComment"
|
2005-11-04 14:39:50 -05:00
|
|
|
has_many :special_comments
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :nonexistent_comments, -> { where "comments.id < 0" }, class_name: "Comment"
|
2010-10-31 07:21:28 -04:00
|
|
|
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :special_comments_ratings, through: :special_comments, source: :ratings
|
|
|
|
has_many :special_comments_ratings_taggings, through: :special_comments_ratings, source: :taggings
|
2005-11-03 04:06:42 -05:00
|
|
|
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :category_posts, class_name: "CategoryPost"
|
2013-08-29 14:49:23 -04:00
|
|
|
has_many :scategories, through: :category_posts, source: :category
|
2005-04-10 13:24:56 -04:00
|
|
|
has_and_belongs_to_many :categories
|
2016-08-06 13:37:57 -04:00
|
|
|
has_and_belongs_to_many :special_categories, join_table: "categories_posts", association_foreign_key: "category_id"
|
2005-12-02 01:03:43 -05:00
|
|
|
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :taggings, as: :taggable, counter_cache: :tags_count
|
|
|
|
has_many :tags, through: :taggings do
|
2006-03-21 11:33:22 -05:00
|
|
|
def add_joins_and_select
|
2016-08-06 12:26:20 -04:00
|
|
|
select("tags.*, authors.id as author_id")
|
|
|
|
.joins("left outer join posts on taggings.taggable_id = posts.id left outer join authors on posts.author_id = authors.id")
|
2012-07-27 12:27:47 -04:00
|
|
|
.to_a
|
2006-03-21 11:33:22 -05:00
|
|
|
end
|
|
|
|
end
|
2008-01-18 02:27:03 -05:00
|
|
|
|
2018-01-14 15:46:19 -05:00
|
|
|
has_many :indestructible_taggings, as: :taggable, counter_cache: :indestructible_tags_count
|
|
|
|
has_many :indestructible_tags, through: :indestructible_taggings, source: :tag
|
|
|
|
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :taggings_with_delete_all, class_name: "Tagging", as: :taggable, dependent: :delete_all, counter_cache: :taggings_with_delete_all_count
|
|
|
|
has_many :taggings_with_destroy, class_name: "Tagging", as: :taggable, dependent: :destroy, counter_cache: :taggings_with_destroy_count
|
2011-02-05 08:13:49 -05:00
|
|
|
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :tags_with_destroy, through: :taggings, source: :tag, dependent: :destroy, counter_cache: :tags_with_destroy_count
|
|
|
|
has_many :tags_with_nullify, through: :taggings, source: :tag, dependent: :nullify, counter_cache: :tags_with_nullify_count
|
2010-12-17 15:54:50 -05:00
|
|
|
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :misc_tags, -> { where tags: { name: "Misc" } }, through: :taggings, source: :tag
|
|
|
|
has_many :funky_tags, through: :taggings, source: :tag
|
|
|
|
has_many :super_tags, through: :taggings
|
2017-10-26 19:22:16 -04:00
|
|
|
has_many :ordered_tags, through: :taggings
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :tags_with_primary_key, through: :taggings, source: :tag_with_primary_key
|
|
|
|
has_one :tagging, as: :taggable
|
2010-10-31 07:21:28 -04:00
|
|
|
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :first_taggings, -> { where taggings: { comment: "first" } }, as: :taggable, class_name: "Tagging"
|
|
|
|
has_many :first_blue_tags, -> { where tags: { name: "Blue" } }, through: :first_taggings, source: :tag
|
2010-10-18 19:27:40 -04:00
|
|
|
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :first_blue_tags_2, -> { where taggings: { comment: "first" } }, through: :taggings, source: :blue_tag
|
2006-02-09 14:37:05 -05:00
|
|
|
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :invalid_taggings, -> { where "taggings.id < 0" }, as: :taggable, class_name: "Tagging"
|
|
|
|
has_many :invalid_tags, through: :invalid_taggings, source: :tag
|
2006-03-18 18:14:31 -05:00
|
|
|
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :categorizations, foreign_key: :category_id
|
|
|
|
has_many :authors, through: :categorizations
|
2006-01-21 18:40:20 -05:00
|
|
|
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :categorizations_using_author_id, primary_key: :author_id, foreign_key: :post_id, class_name: "Categorization"
|
|
|
|
has_many :authors_using_author_id, through: :categorizations_using_author_id, source: :author
|
2010-12-15 18:27:15 -05:00
|
|
|
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :taggings_using_author_id, primary_key: :author_id, as: :taggable, class_name: "Tagging"
|
|
|
|
has_many :tags_using_author_id, through: :taggings_using_author_id, source: :tag
|
2010-12-15 18:27:15 -05:00
|
|
|
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :images, as: :imageable, foreign_key: :imageable_identifier, foreign_type: :imageable_class
|
|
|
|
has_one :main_image, as: :imageable, foreign_key: :imageable_identifier, foreign_type: :imageable_class, class_name: "Image"
|
2014-12-08 14:43:16 -05:00
|
|
|
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :standard_categorizations, class_name: "Categorization", foreign_key: :post_id
|
|
|
|
has_many :author_using_custom_pk, through: :standard_categorizations
|
|
|
|
has_many :authors_using_custom_pk, through: :standard_categorizations
|
|
|
|
has_many :named_categories, through: :standard_categorizations
|
2010-12-15 18:27:15 -05:00
|
|
|
|
2006-02-10 00:19:41 -05:00
|
|
|
has_many :readers
|
2012-03-04 22:45:17 -05:00
|
|
|
has_many :secure_readers
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :readers_with_person, -> { includes(:person) }, class_name: "Reader"
|
|
|
|
has_many :people, through: :readers
|
|
|
|
has_many :single_people, through: :readers
|
|
|
|
has_many :people_with_callbacks, source: :person, through: :readers,
|
2016-08-16 03:30:11 -04:00
|
|
|
before_add: lambda { |owner, reader| log(:added, :before, reader.first_name) },
|
|
|
|
after_add: lambda { |owner, reader| log(:added, :after, reader.first_name) },
|
|
|
|
before_remove: lambda { |owner, reader| log(:removed, :before, reader.first_name) },
|
|
|
|
after_remove: lambda { |owner, reader| log(:removed, :after, reader.first_name) }
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :skimmers, -> { where skimmer: true }, class_name: "Reader"
|
|
|
|
has_many :impatient_people, through: :skimmers, source: :person
|
2008-04-05 20:27:12 -04:00
|
|
|
|
2012-08-28 15:48:59 -04:00
|
|
|
has_many :lazy_readers
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :lazy_readers_skimmers_or_not, -> { where(skimmer: [ true, false ]) }, class_name: "LazyReader"
|
2012-08-28 15:48:59 -04:00
|
|
|
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :lazy_people, through: :lazy_readers, source: :person
|
|
|
|
has_many :lazy_readers_unscope_skimmers, -> { skimmers_or_not }, class_name: "LazyReader"
|
|
|
|
has_many :lazy_people_unscope_skimmers, through: :lazy_readers_unscope_skimmers, source: :person
|
2012-08-28 15:48:59 -04:00
|
|
|
|
2009-02-13 01:07:39 -05:00
|
|
|
def self.top(limit)
|
2010-01-17 11:04:26 -05:00
|
|
|
ranked_by_comments.limit_by(limit)
|
2009-02-13 01:07:39 -05:00
|
|
|
end
|
|
|
|
|
2014-04-01 23:18:16 -04:00
|
|
|
def self.written_by(author)
|
|
|
|
where(id: author.posts.pluck(:id))
|
|
|
|
end
|
|
|
|
|
2008-04-05 20:27:12 -04:00
|
|
|
def self.reset_log
|
|
|
|
@log = []
|
|
|
|
end
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2016-10-28 23:05:58 -04:00
|
|
|
def self.log(message = nil, side = nil, new_record = nil)
|
2008-04-05 20:27:12 -04:00
|
|
|
return @log if message.nil?
|
|
|
|
@log << [message, side, new_record]
|
|
|
|
end
|
2005-04-10 11:49:49 -04:00
|
|
|
end
|
|
|
|
|
2006-12-01 16:24:47 -05:00
|
|
|
class SpecialPost < Post; end
|
2005-07-03 04:21:22 -04:00
|
|
|
|
|
|
|
class StiPost < Post
|
2016-08-06 13:37:57 -04:00
|
|
|
has_one :special_comment, class_name: "SpecialComment"
|
2005-07-03 04:21:22 -04:00
|
|
|
end
|
2006-03-15 21:46:01 -05:00
|
|
|
|
2017-08-12 13:29:27 -04:00
|
|
|
class AbstractStiPost < Post
|
|
|
|
self.abstract_class = true
|
|
|
|
end
|
|
|
|
|
2006-03-15 21:46:01 -05:00
|
|
|
class SubStiPost < StiPost
|
2006-12-01 16:24:47 -05:00
|
|
|
self.table_name = Post.table_name
|
2006-03-15 21:46:01 -05:00
|
|
|
end
|
2010-01-23 03:10:38 -05:00
|
|
|
|
2017-08-12 13:29:27 -04:00
|
|
|
class SubAbstractStiPost < AbstractStiPost; end
|
|
|
|
|
2019-04-05 23:00:17 -04:00
|
|
|
class NullPost < Post
|
|
|
|
default_scope { none }
|
|
|
|
end
|
|
|
|
|
2010-12-12 11:35:27 -05:00
|
|
|
class FirstPost < ActiveRecord::Base
|
2015-03-24 11:09:46 -04:00
|
|
|
self.inheritance_column = :disabled
|
2016-08-06 12:26:20 -04:00
|
|
|
self.table_name = "posts"
|
2016-08-06 13:37:57 -04:00
|
|
|
default_scope { where(id: 1) }
|
2011-04-03 19:07:45 -04:00
|
|
|
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :comments, foreign_key: :post_id
|
|
|
|
has_one :comment, foreign_key: :post_id
|
2010-12-12 11:35:27 -05:00
|
|
|
end
|
2011-05-24 02:21:32 -04:00
|
|
|
|
2019-03-03 08:39:45 -05:00
|
|
|
class PostWithDefaultSelect < ActiveRecord::Base
|
|
|
|
self.table_name = "posts"
|
|
|
|
|
|
|
|
default_scope { select(:author_id) }
|
|
|
|
end
|
|
|
|
|
2017-05-17 21:42:26 -04:00
|
|
|
class TaggedPost < Post
|
|
|
|
has_many :taggings, -> { rewhere(taggable_type: "TaggedPost") }, as: :taggable
|
|
|
|
has_many :tags, through: :taggings
|
|
|
|
end
|
|
|
|
|
2011-05-24 02:21:32 -04:00
|
|
|
class PostWithDefaultInclude < ActiveRecord::Base
|
2015-03-24 11:09:46 -04:00
|
|
|
self.inheritance_column = :disabled
|
2016-08-06 12:26:20 -04:00
|
|
|
self.table_name = "posts"
|
2012-03-21 18:18:18 -04:00
|
|
|
default_scope { includes(:comments) }
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :comments, foreign_key: :post_id
|
2011-09-04 14:42:57 -04:00
|
|
|
end
|
|
|
|
|
2013-01-14 15:39:51 -05:00
|
|
|
class PostWithSpecialCategorization < Post
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :categorizations, foreign_key: :post_id
|
|
|
|
default_scope { where(type: "PostWithSpecialCategorization").joins(:categorizations).where(categorizations: { special: true }) }
|
2013-01-14 15:39:51 -05:00
|
|
|
end
|
|
|
|
|
2011-09-04 14:42:57 -04:00
|
|
|
class PostWithDefaultScope < ActiveRecord::Base
|
2015-03-24 11:09:46 -04:00
|
|
|
self.inheritance_column = :disabled
|
2016-08-06 12:26:20 -04:00
|
|
|
self.table_name = "posts"
|
2012-03-21 18:18:18 -04:00
|
|
|
default_scope { order(:title) }
|
2011-09-04 14:42:57 -04:00
|
|
|
end
|
|
|
|
|
2015-07-07 12:38:54 -04:00
|
|
|
class PostWithPreloadDefaultScope < ActiveRecord::Base
|
2016-08-06 12:26:20 -04:00
|
|
|
self.table_name = "posts"
|
2015-07-07 12:38:54 -04:00
|
|
|
|
2016-08-06 12:26:20 -04:00
|
|
|
has_many :readers, foreign_key: "post_id"
|
2015-07-07 12:38:54 -04:00
|
|
|
|
|
|
|
default_scope { preload(:readers) }
|
|
|
|
end
|
|
|
|
|
|
|
|
class PostWithIncludesDefaultScope < ActiveRecord::Base
|
2016-08-06 12:26:20 -04:00
|
|
|
self.table_name = "posts"
|
2015-07-07 12:38:54 -04:00
|
|
|
|
2016-08-06 12:26:20 -04:00
|
|
|
has_many :readers, foreign_key: "post_id"
|
2015-07-07 12:38:54 -04:00
|
|
|
|
|
|
|
default_scope { includes(:readers) }
|
|
|
|
end
|
|
|
|
|
2011-09-04 14:42:57 -04:00
|
|
|
class SpecialPostWithDefaultScope < ActiveRecord::Base
|
2015-03-24 11:09:46 -04:00
|
|
|
self.inheritance_column = :disabled
|
2016-08-06 12:26:20 -04:00
|
|
|
self.table_name = "posts"
|
2016-10-28 23:05:58 -04:00
|
|
|
default_scope { where(id: [1, 5, 6]) }
|
2018-07-18 18:52:53 -04:00
|
|
|
scope :unscoped_all, -> { unscoped { all } }
|
2018-11-29 15:50:40 -05:00
|
|
|
scope :authorless, -> { unscoped { where(author_id: 0) } }
|
2011-12-08 14:58:59 -05:00
|
|
|
end
|
2014-05-12 17:30:05 -04:00
|
|
|
|
|
|
|
class PostThatLoadsCommentsInAnAfterSaveHook < ActiveRecord::Base
|
2015-03-24 11:09:46 -04:00
|
|
|
self.inheritance_column = :disabled
|
2016-08-06 12:26:20 -04:00
|
|
|
self.table_name = "posts"
|
2014-05-12 17:30:05 -04:00
|
|
|
has_many :comments, class_name: "CommentThatAutomaticallyAltersPostBody", foreign_key: :post_id
|
2014-05-14 19:29:30 -04:00
|
|
|
|
2014-05-12 17:30:05 -04:00
|
|
|
after_save do |post|
|
|
|
|
post.comments.load
|
|
|
|
end
|
|
|
|
end
|
2014-08-31 15:18:02 -04:00
|
|
|
|
2014-10-13 10:50:32 -04:00
|
|
|
class PostWithAfterCreateCallback < ActiveRecord::Base
|
2015-03-24 11:09:46 -04:00
|
|
|
self.inheritance_column = :disabled
|
2016-08-06 12:26:20 -04:00
|
|
|
self.table_name = "posts"
|
2014-10-13 10:50:32 -04:00
|
|
|
has_many :comments, foreign_key: :post_id
|
|
|
|
|
|
|
|
after_create do |post|
|
|
|
|
update_attribute(:author_id, comments.first.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-31 15:18:02 -04:00
|
|
|
class PostWithCommentWithDefaultScopeReferencesAssociation < ActiveRecord::Base
|
2015-03-24 11:09:46 -04:00
|
|
|
self.inheritance_column = :disabled
|
2016-08-06 12:26:20 -04:00
|
|
|
self.table_name = "posts"
|
2014-08-31 15:18:02 -04:00
|
|
|
has_many :comment_with_default_scope_references_associations, foreign_key: :post_id
|
|
|
|
has_one :first_comment, class_name: "CommentWithDefaultScopeReferencesAssociation", foreign_key: :post_id
|
|
|
|
end
|
2014-10-31 11:43:38 -04:00
|
|
|
|
|
|
|
class SerializedPost < ActiveRecord::Base
|
|
|
|
serialize :title
|
|
|
|
end
|
2016-01-11 01:03:16 -05:00
|
|
|
|
|
|
|
class ConditionalStiPost < Post
|
2016-08-06 12:26:20 -04:00
|
|
|
default_scope { where(title: "Untitled") }
|
2016-01-11 01:03:16 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class SubConditionalStiPost < ConditionalStiPost
|
|
|
|
end
|
2017-07-10 18:40:26 -04:00
|
|
|
|
|
|
|
class FakeKlass
|
|
|
|
extend ActiveRecord::Delegation::DelegateCache
|
|
|
|
|
|
|
|
class << self
|
|
|
|
def connection
|
|
|
|
Post.connection
|
|
|
|
end
|
|
|
|
|
|
|
|
def table_name
|
|
|
|
"posts"
|
|
|
|
end
|
|
|
|
|
2019-04-22 05:12:14 -04:00
|
|
|
def attribute_aliases
|
|
|
|
{}
|
2017-07-10 18:40:26 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def sanitize_sql(sql)
|
|
|
|
sql
|
|
|
|
end
|
|
|
|
|
|
|
|
def sanitize_sql_for_order(sql)
|
|
|
|
sql
|
|
|
|
end
|
|
|
|
|
|
|
|
def arel_attribute(name, table)
|
|
|
|
table[name]
|
|
|
|
end
|
2017-09-25 12:58:08 -04:00
|
|
|
|
2018-08-27 09:30:05 -04:00
|
|
|
def disallow_raw_sql!(*args)
|
2017-09-25 12:58:08 -04:00
|
|
|
# noop
|
|
|
|
end
|
2018-01-24 14:06:30 -05:00
|
|
|
|
2019-02-16 11:56:18 -05:00
|
|
|
def columns_hash
|
|
|
|
{ "name" => nil }
|
|
|
|
end
|
|
|
|
|
2018-01-24 14:06:30 -05:00
|
|
|
def arel_table
|
|
|
|
Post.arel_table
|
|
|
|
end
|
|
|
|
|
|
|
|
def predicate_builder
|
|
|
|
Post.predicate_builder
|
|
|
|
end
|
2018-10-08 03:45:05 -04:00
|
|
|
|
|
|
|
def base_class?
|
|
|
|
true
|
|
|
|
end
|
2017-07-10 18:40:26 -04:00
|
|
|
end
|
2018-10-08 03:45:05 -04:00
|
|
|
|
|
|
|
inherited self
|
2017-07-10 18:40:26 -04:00
|
|
|
end
|