Sha256: 848c52a8ae0b11c5ceece86ecabcf5ab0c4e2b18cef82adee47c7ea7d7b82cf3

Contents?: true

Size: 825 Bytes

Versions: 2

Compression:

Stored size: 825 Bytes

Contents

class Post < ActiveRecord::Base
  has_many :comments
  belongs_to :user

  calculated :comments_count, -> { 'select count(*) from comments where comments.post_id = posts.id' }
  calculated :comments_two, -> { 'select count(*) from comments where comments.post_id = posts.id' }
  calculated :comments_arel, -> { Comment.where(Comment.arel_table[:post_id].eq(Post.arel_table[:id])).select(Arel.sql('count(*)')) }
  calculated :comments_to_sql, -> { Comment.where('comments.post_id = posts.id').select('count(*)') }
end

class Tutorial < Post
end

class Article < Post
  calculated :sub_comments, -> { 'select count(*) from comments where comments.post_id = posts.id' }
end

class Comment < ActiveRecord::Base
  belongs_to :post
  belongs_to :user
end

class User < ActiveRecord::Base
  has_many :comments
  has_many :posts
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
calculated_attributes-0.1.3 spec/support/models.rb
calculated_attributes-0.1.2 spec/support/models.rb