开发者

Rails 3 - Awesome Nested Set - Comment.rebuild! - Results in a ERROR

I'm using the awesome_nested_set rails 3 fork here: https://github.com/FreakyDazio/awesome_nested_set

I'm trying to rebuild the nesting per the installation instructions.

I went to console and typed in:

>>Comment.rebuild!

But that errors with:

ActiveRecord::StatementInvalid: PGError: ERROR:  column "comments.created_at" must appear in the GROUP BY clause or be used in an aggregate function
LINE 2:                 HAVING COUNT("lft") >开发者_StackOverflow 1 ORDER BY comments.cr...
                                                         ^
: SELECT "lft", COUNT("lft") FROM "comments" GROUP BY "lft" 
                HAVING COUNT("lft") > 1 ORDER BY comments.created_at DESC LIMIT 1

Any thoughts or ideas why?

Thanks


This same issues is reported in another fork of acts_as_nested_set (you seem to have all the bad luck. :) See this error report. He does mention a workaround you can put in your model:

def self.all_roots_valid?
  if acts_as_nested_set_options[:scope]
    roots.group_by{|record| scope_column_names.collect{|col| record.send(col.to_sym)}}.all? do |scope, grouped_roots|
      each_root_valid?(grouped_roots)
    end
  else
    each_root_valid?(roots)
  end
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜