mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 18:30:26 -06:00
DEV: prefer using ordering in relation over default scope
This commit is contained in:
parent
16d0ab5654
commit
df815d6c0e
@ -48,7 +48,7 @@ class Post < ActiveRecord::Base
|
||||
has_many :post_details
|
||||
|
||||
has_many :post_revisions
|
||||
has_many :revisions, foreign_key: :post_id, class_name: 'PostRevision'
|
||||
has_many :revisions, -> { order(:number) }, foreign_key: :post_id, class_name: 'PostRevision'
|
||||
|
||||
has_many :user_actions, foreign_key: :target_post_id
|
||||
|
||||
|
@ -4,8 +4,6 @@ class PostRevision < ActiveRecord::Base
|
||||
belongs_to :post
|
||||
belongs_to :user
|
||||
|
||||
default_scope { order('number ASC') }
|
||||
|
||||
serialize :modifications, Hash
|
||||
|
||||
after_create :create_notification
|
||||
|
@ -1095,4 +1095,11 @@ describe Post do
|
||||
expect(hidden_topic.visible).to eq(false)
|
||||
end
|
||||
|
||||
it "automatically orders post revisions by number ascending" do
|
||||
post = Fabricate(:post)
|
||||
post.revisions.create!(user_id: 1, post_id: post.id, number: 2)
|
||||
post.revisions.create!(user_id: 1, post_id: post.id, number: 1)
|
||||
expect(post.revisions.pluck(:number)).to eq([1, 2])
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user