环境:
我的问题是: 我有博客,发布模型如:
class Blog
include Mongoid::Document
fields ~
has_many :posts
end
class Post
include Mongoid::Document
fields ~
belongs_to :blog
end
然后我在Rakefile中尝试这个
task :my_test do
ENV['RACK_ENV'] = 'development'
require "api.rb" #it will require all models、..etc
blog = Blog.where(urlname: "testblog").first
** p blog ** #this will output only blog attributes without posts
** p JSON.parse(blog.to_json) ** #this will output blog blog attrs and all it's post
end
我不知道是什么导致他们之间出现这种差异
感谢