Hello, I have a case that works under MySQL but causes a crash in SQLServer. I have two models Feed and Publisher that have a HABTM relationship.
class Feed < ActiveRecord::Base belongs_to :publisher has_and_belongs_to_many :publications validates_presence_of :publisher, :message => "You must select a publisher" validates_associated :publisher validates_presence_of :name, :message => "You must supply a name" end class Publication < ActiveRecord::Base belongs_to :publisher has_and_belongs_to_many :feeds validates_presence_of :name, :message => "You must supply a name" validates_uniqueness_of :name validates_presence_of :publisher, :message => "You must select a publisher" validates_associated :publisher end The controllers just have active_scaffold :model where :model = :feed or :publication depending on which controller you are in. If I create a feed and a publication, all displays fine. But when I connect the two together by creating a record in the feed_publication table, I get a crazy error I can't figure out (only on SQLServer). I can actually use AS to create the association. After the save, the view shows the correct record with the new association. But if I reload the whole page by going back to the controller :index page, I get this error. I get the same error if I try to load the :index method on the controller on the opposite end of the HABTM as well. So, once there is a record in the join table, both controllers now throw this error. If I take the HABTM relationship out of the AS (with config.columns = [:blah, :blah2] leaving out :feeds or :publications depending on which controller you are in) the error goes away. Of course I can't edit the relationship which is the whole idea here. Sorry for the long post, I hope the detail is valuable. It's kind of a hard stop for using AS for admin if I can't edit some key relationships like this. Stack trace from the error Processing FeedsController#index (for 127.0.0.1 at 2009-06-09 09:13:41) [GET] User Load (0.8ms) SELECT * FROM [user] WHERE ([user].[id] = 1) SQL (3.0ms) SELECT count(DISTINCT [feed].id) AS count_all FROM [feed] LEFT OUTER JOIN [article] ON article.feed_id = feed.id LEFT OUTER JOIN [publisher] ON [publisher].id = [feed].publisher_id LEFT OUTER JOIN [feed_publication] ON [feed_publication].feed_id = [feed].id LEFT OUTER JOIN [publication] ON [publication].id = [feed_publication].publication_id SQL (0.4ms) SELECT count(*) as TotalRows from (SELECT TOP 1000000000 [feed].* FROM [feed] ORDER BY feed.[id] ASC) tally Feed Load (0.7ms) SELECT * FROM (SELECT TOP 1 * FROM (SELECT TOP 1 [feed].* FROM [feed] ORDER BY feed.[id] ASC) AS tmp1 ORDER BY id DESC) AS tmp2 ORDER BY id ASC Article Load (1.4ms) SELECT [article].* FROM [article] WHERE ([article].feed_id = 1) Publisher Load (1.1ms) SELECT * FROM [publisher] WHERE ([publisher].[id] = 1) Publication Load (3.3ms) SELECT [publication].*, t0.feed_id as the_parent_record_id FROM [publication] INNER JOIN [feed_publication] t0 ON [publication].id = t0.publication_id WHERE (t0.feed_id = 1) NoMethodError (You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each): /usr/lib/ruby/1.8/mongrel.rb:159:in `process_client' /usr/lib/ruby/1.8/mongrel.rb:158:in `each' /usr/lib/ruby/1.8/mongrel.rb:158:in `process_client' /usr/lib/ruby/1.8/mongrel.rb:285:in `run' /usr/lib/ruby/1.8/mongrel.rb:285:in `initialize' /usr/lib/ruby/1.8/mongrel.rb:285:in `new' /usr/lib/ruby/1.8/mongrel.rb:285:in `run' /usr/lib/ruby/1.8/mongrel.rb:268:in `initialize' /usr/lib/ruby/1.8/mongrel.rb:268:in `new' /usr/lib/ruby/1.8/mongrel.rb:268:in `run' Rendered rescues/_trace (221.5ms) Rendered rescues/_request_and_response (0.4ms) Rendering rescues/layout (internal_server_error) NOTE: config.active_record.pluralize_table_names = false The SQLServer guys are kind of old school and can't take :people naming a table that holds :person records. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "ActiveScaffold : Ruby on Rails plugin" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/activescaffold?hl=en -~----------~----~----~----~------~----~------~--~---
