Trong giao diện điều khiển:nhổ và id cho mảng của các yếu tố phi độc đáo
Course.ids.count
=> 1766
Course.pluck(:id).count
=> 1766
Course.ids.uniq.count
=> 1529
Course.count
=> 1529
Đó là bình thường không?
nhận xét nhỏ - mô hình Khóa học sử dụng tổ tiên (đá quý).
UPD1:
tạo sql:
Learn::Course.ids.count
(5.4ms) SELECT "learn_courses"."id" FROM "learn_courses" LEFT OUTER JOIN "learn_course_translations" ON "learn_course_translations"."learn_course_id" = "learn_courses"."id"
=> 1766
Learn::Course.count
(1.5ms) SELECT COUNT(*) FROM "learn_courses"
=> 1529
hmm ...
UPD2:
Schema Thông tin
#
# Table name: learn_courses
#
# id :integer not null, primary key
# name :string(255)
# position :integer
# created_at :datetime
# updated_at :datetime
# ancestry :string(255)
# course_type :string(255)
# article :string(255)
# item_style :integer
# hidden :boolean
# score :integer default(0)
# next_id :integer
# first :boolean
'ids' ở đây là gì? –
@MaxWilliams http://api.rubyonrails.org/classes/ActiveRecord/Calculations.html#method-i-ids –
Bạn có thể xem nhật ký của mình và xem sql được tạo bởi mỗi lệnh khác nhau hay không và thêm chúng dưới mỗi lệnh trong câu hỏi của bạn? –