如何处理无法将相关记录保存到数据库的场景?
如果我有
-(void)viewWillAppear:(BOOL)animated{
if(!self.isViewExist){
self.isViewExist = YES; // check it is the first time you go to this ViewController -> don't reload anything
}else{
[self.tableView reloadData]; // to reload the tableview data
// or your can refresh anything in your ViewController as you want
}
}
然后为急切加载添加class Blog < ActiveRecord::Base
has_many :posts
end
class Post < ActiveRecord::Base
has_many :comments
end
语句会丢弃未保存的记录:
includes
我可以省略blog = Blog.new
blog.posts << Post.new
blog.posts # => Return value contains one post
blog.posts.includes(:comments) # => Empty result
声明,但如果我的代码与评论互动并且博客和帖子已保存,则表示代码速度较慢。
我使用的是Rails 4.1。