On Lunes, 1 de Febrero de 2010 09:23:09 [email protected] escribió: > Hi, > > Well, I would suggest to do the following: > > class User < ActiveRecord::Base > has_many :schoolclass_users > has_many :schoolclasses, :through => :schoolclass_users > end > > class Schoolclass < ActiveRecord::Base > has_many :schoolclass_users > has_many :users, :through => :schoolclass_users > end > > In addition I would recommend to not use a singularized table_name: > "schoolclass_user".
I think you will have to add set_table_name 'schoolclass_user' to SchoolclassUser if you don't rename the table. Anyway, I would remove SchoolclassUser, rename schoolclass_user to schoolclasses_users, add :id => false to migration of schoolclasses_users and use has_and_belongs_to_many instead of has_many :through > > At least this configuration works for me. Without the additional > associations in the models I could reproduce your klass nil exception. > > -- > volker > > On 30 Jan., 21:51, Soren <[email protected]> wrote: > > Tried to build a really simple test case to understand a problem in > > another tread. > > Leads to the same problem as previously: > > > > undefined method `klass' for nil:NilClass > > /usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/ > > whiny_nil.rb:52:in `method_missing' > > /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/ > > reflection.rb:257:in `source_reflection' > > /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/ > > reflection.rb:257:in `collect' > > /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/ > > reflection.rb:257:in `source_reflection' > > /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/ > > reflection.rb:316:in `derive_class_name' > > /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/ > > reflection.rb:112:in `class_name' > > /home/soren/tmp/test/vendor/plugins/active_scaffold/lib/extensions/ > > reverse_associations.rb:11:in `reverse' > > /home/soren/tmp/test/vendor/plugins/active_scaffold/lib/ > > active_scaffold/data_structures/column.rb:117:in `autolink?' > > /home/soren/tmp/test/vendor/plugins/active_scaffold/lib/ > > active_scaffold.rb:107:in `links_for_associations' > > /home/soren/tmp/test/vendor/plugins/active_scaffold/lib/ > > active_scaffold/data_structures/columns.rb:62:in `each' > > /home/soren/tmp/test/vendor/plugins/active_scaffold/lib/ > > active_scaffold/data_structures/columns.rb:62:in `each' > > /home/soren/tmp/test/vendor/plugins/active_scaffold/lib/ > > active_scaffold.rb:106:in `links_for_associations' > > /home/soren/tmp/test/vendor/plugins/active_scaffold/lib/ > > active_scaffold.rb:59:in `active_scaffold' > > /home/soren/tmp/test/app/controllers/schoolclasses_controller.rb:5 > > > > Here is my models: > > class Schoolclass < ActiveRecord::Base > > > > has_many :users, :through => :schoolclass_user > > > > end > > > > class SchoolclassUser < ActiveRecord::Base > > > > belongs_to :schoolclass > > belongs_to :user > > > > end > > > > class User < ActiveRecord::Base > > > > has_many :schoolclasses, :through => :schoolclass_user > > > > end > > > > Here is my controllers > > class SchoolclassesController < ApplicationController > > > > layout "default" > > > > active_scaffold :schoolclasses do |config| > > > > end > > > > end > > > > class UsersController < ApplicationController > > > > layout "default" > > > > active_scaffold :user do |config| > > > > end > > > > end > > > > And the schema is : > > > > create_table "schoolclass_user", :force => true do |t| > > t.datetime "created_at" > > t.datetime "updated_at" > > t.integer "user_id" > > t.integer "schoolclass_id" > > end > > > > create_table "schoolclasses", :force => true do |t| > > t.datetime "created_at" > > t.datetime "updated_at" > > t.string "name" > > t.integer "grade" > > end > > > > create_table "users", :force => true do |t| > > t.datetime "created_at" > > t.datetime "updated_at" > > t.string "first_name" > > t.string "last_name" > > end > > > > Adding the > > config.columns[:schooclasses].association.reverse = :user > > config.columns[:users].association.reverse = :schoolclass > > > > does not help. > > > > Did I hit a bug in AS or do I have some gross oversight somewhere that > > prevents this from working ? > > > > /S -- Sergio Cambra .:: entreCables S.L. ::. Mariana Pineda 23, 50.018 Zaragoza T) 902 021 404 F) 976 52 98 07 E) [email protected] -- 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.
