SystemStackError: stack level too deep

my code is ;

$ssf def find_class(class_name, stack = )   FileClass.find(:all, :conditions => ["class_name = ?", class_name]).each do |file_class|       FileInclude.find(:all, :conditions => ["file_name = ?", file_class.file_name]).each do |file_include|         FileClass.find(:all, :conditions => ["file_name = ?", file_include.file_name]).each do |xxxx|           next if stack.include?(xxxx.class_name)             begin            find_class(file_class.class_name, stack)

              p file_class               p "============================"               p file_include               p "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------"               p xxxx             rescue SystemStackError => ssf               p $ssf = ssf             end

        end       end     end   end

rake aborted! SystemStackError: stack level too deep: SELECT * FROM `file_includes` WHERE (file_name = 'IMAgentHome')

C:/Base/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:212:in `log' C:/Base/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:320:in `execute' C:/Base/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:595:in `select' .....

help me please!

help me please!

Well you seem to be recursing in a pretty uncontrolled way.

Fred

You have not mentioned how should recursion stop properly. Anyway, code also doesnt look very clean and I think not very efficient too. My suggestion is first fetch all FileClass using conditions in an array, include all the FileInclude as well (using :include) Then select, reject the record you want to.

Sorry, if I haven’t understood your problem correctly.

Hi,

Can you put in a statement what you are trying to do, probably then I (and others) will be able to help you better.

Abhinav Saxena wrote:

Hi,

Can you put in a statement what you are trying to do, probably then I (and others) will be able to help you better.

-- Thanks, Abhinav http://twitter.com/abhinav

On Thu, Sep 3, 2009 at 3:19 PM, Ahmet Kilic <

thanks, I improved my code, but still not enough its giving me double result

def find_class(class_name, stack = )    puts(("\t" * stack.size) + class_name)

    stack.push class_name     FileClass.find(:all, :conditions => ["class_name = ?", class_name]).each do |file_class|       p file_class.file_name + "aaa"       FileInclude.find(:all, :conditions => ["file_name = ?", file_class.file_name]).each do |file_include|

          p file_include.include_file_name + "bbb"           FileClass.find(:all, :conditions => ["file_name = ?", file_include.file_name]).each do |file_class|

          p file_class.class_name + "ccc"           next if stack.include?(file_class.class_name)

          find_class(file_include.include_file_name, stack)         end       end     end    stack.pop   end

Help me understand what you are trying to accomplish (please put in words)

I am trying to recursive call. An the resut should be like this

resullts