我这样调用 first_or_create :
collection = Collection.first_or_create(:title => title)
有没有办法确定结果是现有条目还是新创建的条目?到目前为止,我想出的最佳解决方案是使用 first_or_initialize:
collection = Collection.first_or_initialize(:title => title)
if collection.id.nil?
<process>
collection.save
end
但这感觉有点hacky。有没有办法直接从 first_or_create 获取这些信息?