We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8238c6e commit 0668de9Copy full SHA for 0668de9
app/models/topic.rb
@@ -157,7 +157,7 @@ def destroy
157
# 所有的回复编号
158
def reply_ids
159
Rails.cache.fetch([self, 'reply_ids']) do
160
- replies.only(:id).map(&:id).sort
+ self.replies.order('id asc').pluck(:id)
161
end
162
163
spec/models/topic_spec.rb
@@ -248,4 +248,13 @@
248
expect(t.lock_node).to eq true
249
250
251
+
252
+ describe '.reply_ids' do
253
+ let(:t) { create(:topic) }
254
+ let!(:replies) { create_list(:reply, 10, topic: t) }
255
256
+ it 'should work' do
257
+ expect(t.reply_ids).to eq replies.collect(&:id)
258
+ end
259
260
0 commit comments