Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 未定义的方法`在'更新";对于#<;MatchResult::ActiveRecord_关系:0x0000000232e608>;在轨_Mysql_Ruby On Rails_Arrays - Fatal编程技术网

Mysql 未定义的方法`在'更新";对于#<;MatchResult::ActiveRecord_关系:0x0000000232e608>;在轨

Mysql 未定义的方法`在'更新";对于#<;MatchResult::ActiveRecord_关系:0x0000000232e608>;在轨,mysql,ruby-on-rails,arrays,Mysql,Ruby On Rails,Arrays,我有两个活动记录数组。我合并了这两个数组,现在我想根据“updated_at”字段对它们进行排序 工作正常。 但我想检查@match_results或@notification_challenges是否为空,因此我将合并这两个数组,然后应用“sort_by”函数 MatchResult在您的示例中,可能会返回一个MatchResult对象,其中包含一个记录数组,因此当您将MatchResult添加到第一个数组中时,您将得到如下结果: [a、b、c、MatchResult[d、e、f] 其中,该数

我有两个活动记录数组。我合并了这两个数组,现在我想根据“updated_at”字段对它们进行排序

工作正常。
但我想检查@match_results或@notification_challenges是否为空,因此我将合并这两个数组,然后应用“sort_by”函数

MatchResult
在您的示例中,可能会返回一个
MatchResult
对象,其中包含一个记录数组,因此当您将
MatchResult
添加到第一个数组中时,您将得到如下结果:

[a、b、c、MatchResult[d、e、f]

其中,该数组中的第四个元素是
MatchResult
对象,该对象在属性或方法处没有
update\u

您可以尝试在
MatchResult
中循环搜索结果,并将每个结果推入第一个数组:

results = MatchResult.where("challenge_id=? and result_confirmation_status=?" ,k.id,1)
@match_results = results.map{|c| @match_results << c}
results=MatchResult.where(“质询\确认\结果状态=?”,k.id,1)
@match|u results=results.map{c|@match|u results
已经返回一个数组(坦率地说是ActiveRecord::Relation)。因此,不应该推送。您应该添加

我觉得将@notification\u挑战初始化为空数组也更好。以防万一

@notification_challenges=[]
@notification_challenges=Challenge.where("to_id=? and activity_id=?" ,current_user.id,@activity.id)
@match_results=[]
@notification_challenges.each do |k|
@match_results=@match_results + MatchResult.where("challenge_id=? and result_confirmation_status=?" ,k.id,1)
end

使用此代码
@notifications2=(@notifications)。按{e | e[:updated_at]}排序
@notifications=(@match_results+@notification_challenges).sort_by(&:updated_at) 
results = MatchResult.where("challenge_id=? and result_confirmation_status=?" ,k.id,1)
@match_results = results.map{|c| @match_results << c}
MatchResult.where("challenge_id=? and result_confirmation_status=?" ,k.id,1)
@notification_challenges=[]
@notification_challenges=Challenge.where("to_id=? and activity_id=?" ,current_user.id,@activity.id)
@match_results=[]
@notification_challenges.each do |k|
@match_results=@match_results + MatchResult.where("challenge_id=? and result_confirmation_status=?" ,k.id,1)
end