I have Users who can "own" Projects. There is only one owner. Users in general can be authorized to view certain projects. Here is my initial stab at this: class User < ActiveRecord::Base has_many :projects # ownership has_many :project_viewers, :dependent => :destroy has_many :projects, :through => :project_viewers, :uniq => true ... end class ProjectViewers < ActiveRecord::Base belongs_to :projects belongs_to :users end class Project < ActiveRecord::Base belongs_to :owner, :class_name => ''User'', :foreign_key => ''owner_id'' has_many :project_viewers, :dependent => :destroy has_many :users, :through => :project_viewers, :uniq => true ... end Things appear to work ok until I go to destroy a User, at which point I get: ../activesupport/lib/active_support/dependencies.rb:399:in `to_constant_name'': Anonymous modules have no name to be referenced by (eval):1:in `compute_type'' Any help appreciated this fine Sunday! Thanks, s.ross -- View this message in context: http://www.nabble.com/associations-help--tf2708701.html#a7551954 Sent from the RubyOnRails Users mailing list archive at Nabble.com. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sun, 2006-11-26 at 14:15 -0800, s.ross wrote:> > I have Users who can "own" Projects. There is only one owner. Users in > general can be authorized to view certain projects. Here is my initial stab > at this: > > class User < ActiveRecord::Base > has_many :projects # ownership > has_many :project_viewers, :dependent => :destroy > has_many :projects, :through => :project_viewers, :uniq => true > ... > end > > class ProjectViewers < ActiveRecord::Base > belongs_to :projects > belongs_to :users > end > > class Project < ActiveRecord::Base > belongs_to :owner, :class_name => ''User'', :foreign_key => ''owner_id'' > has_many :project_viewers, :dependent => :destroy > has_many :users, :through => :project_viewers, :uniq => true > ... > end > > Things appear to work ok until I go to destroy a User, at which point I get: > > ../activesupport/lib/active_support/dependencies.rb:399:in > `to_constant_name'': Anonymous modules have no name to be referenced by > (eval):1:in `compute_type'' > > Any help appreciated this fine Sunday!---- Can you have 2 relationships to the same table? Wouldn''t you be better served by having the :dependent => :destroy attached to projects instead? Craig --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I''m not trying to destroy the Project. I''m trying to destroy the record in the join table. Am I missing something? Craig White wrote:> > > On Sun, 2006-11-26 at 14:15 -0800, s.ross wrote: >> >> I have Users who can "own" Projects. There is only one owner. Users in >> general can be authorized to view certain projects. Here is my initial >> stab >> at this: >> >> class User < ActiveRecord::Base >> has_many :projects # ownership >> has_many :project_viewers, :dependent => :destroy >> has_many :projects, :through => :project_viewers, :uniq => true >> ... >> end >> >> class ProjectViewers < ActiveRecord::Base >> belongs_to :projects >> belongs_to :users >> end >> >> class Project < ActiveRecord::Base >> belongs_to :owner, :class_name => ''User'', :foreign_key => ''owner_id'' >> has_many :project_viewers, :dependent => :destroy >> has_many :users, :through => :project_viewers, :uniq => true >> ... >> end >> >> Things appear to work ok until I go to destroy a User, at which point I >> get: >> >> ../activesupport/lib/active_support/dependencies.rb:399:in >> `to_constant_name'': Anonymous modules have no name to be referenced by >> (eval):1:in `compute_type'' >> >> Any help appreciated this fine Sunday! > ---- > Can you have 2 relationships to the same table? Wouldn''t you be better > served by having the :dependent => :destroy attached to projects > instead? > > Craig > > > > > >-- View this message in context: http://www.nabble.com/associations-help--tf2708701.html#a7552202 Sent from the RubyOnRails Users mailing list archive at Nabble.com. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nope - ignore me and my stupid suggestion. ;-) Craig On Sun, 2006-11-26 at 14:44 -0800, s.ross wrote:> > I''m not trying to destroy the Project. I''m trying to destroy the record in > the join table. Am I missing something? > > > Craig White wrote: > > > > > > On Sun, 2006-11-26 at 14:15 -0800, s.ross wrote: > >> > >> I have Users who can "own" Projects. There is only one owner. Users in > >> general can be authorized to view certain projects. Here is my initial > >> stab > >> at this: > >> > >> class User < ActiveRecord::Base > >> has_many :projects # ownership > >> has_many :project_viewers, :dependent => :destroy > >> has_many :projects, :through => :project_viewers, :uniq => true > >> ... > >> end > >> > >> class ProjectViewers < ActiveRecord::Base > >> belongs_to :projects > >> belongs_to :users > >> end > >> > >> class Project < ActiveRecord::Base > >> belongs_to :owner, :class_name => ''User'', :foreign_key => ''owner_id'' > >> has_many :project_viewers, :dependent => :destroy > >> has_many :users, :through => :project_viewers, :uniq => true > >> ... > >> end > >> > >> Things appear to work ok until I go to destroy a User, at which point I > >> get: > >> > >> ../activesupport/lib/active_support/dependencies.rb:399:in > >> `to_constant_name'': Anonymous modules have no name to be referenced by > >> (eval):1:in `compute_type'' > >> > >> Any help appreciated this fine Sunday! > > ---- > > Can you have 2 relationships to the same table? Wouldn''t you be better > > served by having the :dependent => :destroy attached to projects > > instead? > > > > Craig > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I''m having a similar problem, but I get the error when I try to create a new object: class Transfer < ActiveRecord::Base belongs_to :account_id validates_presence_of :account_id .... end class AccountTransfer < Transfer validates_presence_of :matching_transaction_id end class Withdrawal < Transfer validates_presence_of :destination_text end class Deposit < Transfer validates_presence_of :source_text end when I try to create a new object, I get the following error:>> Deposit.create(:account_id=>1)ArgumentError: ./script/../config/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:399:in `to_constant_name'': Anonymous modules have no name to be referenced by from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1363:in `compute_type'' from ./script/../config/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:211:in `qualified_name_for'' from ./script/../config/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:470:in `const_missing'' from (eval):1:in `compute_type'' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/reflection.rb:112:in `klass'' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:147:in `raise_on_type_mismatch'' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/associations/belongs_to_association.rb:22:in `replace'' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/associations.rb:894:in `account_id='' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1660:in `attributes='' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1659:in `attributes='' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1493:in `initialize_without_callbacks'' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/callbacks.rb:225:in `initialize'' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:446:in `create'' from (irb):5 from :0 anyone have any ideas? -Mike -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I figured out the problem -- I stupidly had written "belongs_to :account_id" instead of just "belongs_to :account". Hope this helps someone else save a headache! -Mike -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---