Rails4弃用警告

阿姆里·邓加纳(Amrit Dhungana)

从Rails 3.2升级到Rails 4.0时,Rails4收到折旧警告。我有这个查询。

Child.find(:all, :include => :children_users, :conditions => "state = 'active' AND owner_id = #{self.id} AND children_users.user_id = #{other_user.id}")

我收到以下弃用警告:-

DEPRECATION WARNING: It looks like you are eager loading table(s) (one of: splits, accounts) that are referenced in a string SQL snippet. For example:

    Post.includes(:comments).where("comments.title = 'foo'")

Currently, Active Record recognizes the table in the string, and knows to JOIN the comments table to the query, rather than loading comments in a separate query. However, doing this without writing a full-blown SQL parser is inherently flawed. Since we don't want to write an SQL parser, we are removing this functionality. From now on, you must explicitly tell Active Record when you are referencing a table from a string:

    Post.includes(:comments).where("comments.title = 'foo'").references(:comments)

If you don't rely on implicit join references you can disable the feature entirely by setting `config.active_record.disable_implicit_join_references = true`. (called from splits_under_100_percent at /Users/newimac/RailsApp/bank/app/models/user.rb:274)

为了解决这个问题,我已经尝试过这样

Child.includes(:children_users).where(state: active, owner_id: self.id, children_users.user_id = other_user.id).load

或者

Child.where{(state: active, owner_id: self.id, children_users.user_id = other_user.id).includes(:children_users)}

但是它们都不起作用。

扎万

children_users.user_id = other_user.id 错误的。

正确的是: "children_users.user_id" => other_user.id

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章