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
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’
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:incompute_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?
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:incompute_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:inconst_missing’
from (eval):1:in compute_type' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/reflection.rb:112:inklass’
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:inreplace’
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:inattributes=’
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:ininitialize_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:increate’
from (irb):5
from :0