1

我目前有一个非常奇怪的问题。我有一个ExportFile模型。在byebug测试内部的控制台中,如果我调用.all,我会看到:

>>> ExportFile.all
#<ActiveRecord::Relation [#<ExportFile id: 189, sequence_number: 1, filename: "DB_EXPORT_20151106173840.zip", status: 3, content: 2, created_at: "2015-12-09 12:54:56", updated_at: "2015-12-09 12:54:56", first_transfer_date: nil, failed_transfer_count: 0, successful_transfer_date: "2015-12-01 12:54:56">, #<ExportFile id: 190, sequence_number: 2, filename: "DB_EXPORT_20151106173840.zip", status: 3, content: 2, created_at: "2015-12-09 12:54:56", updated_at: "2015-12-09 12:54:56", first_transfer_date: nil, failed_transfer_count: 0, successful_transfer_date: "2015-12-01 12:54:56">, #<ExportFile id: 191, sequence_number: 3, filename: "DB_EXPORT_20151106173840.zip", status: 3, content: 2, created_at: "2015-12-09 12:54:56", updated_at: "2015-12-09 12:54:56", first_transfer_date: nil, failed_transfer_count: 0, successful_transfer_date: "2015-12-01 12:54:56">, #<ExportFile id: 192, sequence_number: 4, filename: "DB_EXPORT_20151106173840.zip", status: 3, content: 2, created_at: "2015-12-09 12:54:56", updated_at: "2015-12-09 12:54:56", first_transfer_date: nil, failed_transfer_count: 0, successful_transfer_date: "2015-12-01 12:54:56">, #<ExportFile id: 193, sequence_number: 5, filename: "DB_EXPORT_20151106173840.zip", status: 3, content: 2, created_at: "2015-12-09 12:54:56", updated_at: "2015-12-09 12:54:56", first_transfer_date: nil, failed_transfer_count: 0, successful_transfer_date: "2015-12-01 12:54:56">]>

但如果我尝试.count, or .all.to_a,我什么也得不到:

>>> ExportFile.count
0
>>> ExportFile.all.to_a
[]

为什么会发生这种情况,我做错了什么?在运行上面的片段之前,我使用FactoryGirl.create_list(:export_file, 5),如果它确实有所作为。

4

2 回答 2

1

看来升级byebug解决了这个问题。我已经从 8.1.0 升级到 8.2.1。很奇怪...

于 2015-12-09T14:07:37.147 回答
1

我假设您在开发模式下处于控制台中,但 FactoryGirl 在测试数据库中创建记录,因此您无权访问它们。

我认为,如果您在开发数据库中ExportData植入记录,它们就会为您服务。

于 2015-12-09T13:30:37.107 回答