我有一个使用Redis作为数据库的rails应用程序,以及作为ORM的Ohm。
我的模型Activity
有一组Users
。在rails控制台中,我可以调用Activity[id].users.to_a
并获取预期的列表。当我尝试在我的应用程序中的方法中执行相同的操作时,我总是得到一个空字符串。我已经尝试了几种不同的方式,包括在方法中使用self.users.to_a
,但没有任何效果。
我还没有遇到过这样的问题,之前一切都在控制台上工作正常,但在应用程序中却没有。 BTW rails.env设置为开发。
任何帮助都会非常感激,这让我有点困扰。感谢。
Activity.rb
class Activity < Ohm::Model
include Ohm::Timestamps
include Ohm::DataTypes
include Ohm::Callbacks
include ModuleLibrary
attribute :type
index :type
attachment :attached
attribute :time, Type::Integer
attribute :description
attribute :to_calendar, Type::Integer
set :contacts, :Contact
set :users, :User
reference :company, :Company
reference :account, :Account
def user_names #empty string in app, works fine in console
users.map(&:name).to_sentence
end
end
编辑:显然,事实证明我在调用方法的地方,用户还没有被添加。 (呃!)我把这个方法调到了一个不同的地方,它现在都在工作。