Consistent records

This commit is contained in:
Benjamin Fleischer 2017-10-12 23:37:34 -05:00
parent 3fd3a04396
commit 5d3ecb2f16
2 changed files with 7 additions and 3 deletions

View File

@ -13,12 +13,13 @@ module BenchHelper
posts: 20
}
u = User.create(first_name: 'Diana', last_name: 'Prince', birthday: 3000.years.ago)
anchor_time = Time.new(2017,7,1).utc
user = User.create(first_name: 'Diana', last_name: 'Prince', birthday: anchor_time, created_at: anchor_time, updated_at: anchor_time)
data_config[:posts].times do
p = Post.create(user_id: u.id, title: 'Some Post', body: 'awesome content')
post = Post.create(user_id: user.id, title: 'Some Post', body: 'awesome content', created_at: anchor_time, updated_at: anchor_time)
data_config[:comments_per_post].times do
Comment.create(author: 'me', comment: 'nice blog', post_id: p.id)
Comment.create(author: 'me', comment: 'nice blog', post_id: post.id, created_at: anchor_time, updated_at: anchor_time)
end
end
end

View File

@ -36,14 +36,17 @@ class ApplicationRecord < ActiveRecord::Base
end
class Comment < ApplicationRecord
default_scope { order(:id) }
belongs_to :post
end
class Post < ApplicationRecord
default_scope { order(:id) }
has_many :comments
belongs_to :user
end
class User < ApplicationRecord
default_scope { order(:id) }
has_many :posts
end