gpt4 book ai didi

ruby-on-rails-4 - Rails4 弃用警告

转载 作者:行者123 更新时间:2023-12-02 03:37:31 25 4
gpt4 key购买 nike

当我从 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

关于ruby-on-rails-4 - Rails4 弃用警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22452810/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com