# associations help?

**URL:** <https://discuss.rubyonrails.org/t/associations-help/5053>\
**Category:** rubyonrails-talk\
**Created:** [November 26, 2006, 10:15pm UTC](https://discuss.rubyonrails.org/t/associations-help/5053 "2006-11-26T22:15:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steve\_Ross](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@Steve\_Ross](https://discuss.rubyonrails.org/u/Steve_Ross)\
**Post date:** [November 26, 2006, 10:15pm UTC](https://discuss.rubyonrails.org/t/associations-help/5053/1 "2006-11-26T22:15:53Z")

</div>

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 &nbsp;&nbsp;has\_many :projects # ownership &nbsp;&nbsp;has\_many :project\_viewers, :dependent =\> :destroy &nbsp;&nbsp;has\_many :projects, :through =\> :project\_viewers, :uniq =\> true ... end

class ProjectViewers \< ActiveRecord::Base &nbsp;&nbsp;&nbsp;&nbsp;belongs\_to :projects &nbsp;&nbsp;&nbsp;&nbsp;belongs\_to :users end

class Project \< ActiveRecord::Base &nbsp;&nbsp;&nbsp;&nbsp;belongs\_to :owner, :class\_name =\> 'User', :foreign\_key =\> 'owner\_id' &nbsp;&nbsp;&nbsp;&nbsp;has\_many :project\_viewers, :dependent =\> :destroy &nbsp;&nbsp;&nbsp;&nbsp;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

---

<div class="post-metadata">

**Author:** ![Craig\_White2](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@Craig\_White2](https://discuss.rubyonrails.org/u/Craig_White2)\
**Post date:** [November 26, 2006, 10:26pm UTC](https://discuss.rubyonrails.org/t/associations-help/5053/2 "2006-11-26T22:26:58Z")

</div>

> 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 &nbsp;&nbsp;has\_many :projects # ownership &nbsp;&nbsp;has\_many :project\_viewers, :dependent =\> :destroy &nbsp;&nbsp;has\_many :projects, :through =\> :project\_viewers, :uniq =\> true ... end
> 
> class ProjectViewers \< ActiveRecord::Base &nbsp;&nbsp;&nbsp;&nbsp;belongs\_to :projects &nbsp;&nbsp;&nbsp;&nbsp;belongs\_to :users end
> 
> class Project \< ActiveRecord::Base &nbsp;&nbsp;&nbsp;&nbsp;belongs\_to :owner, :class\_name =\> 'User', :foreign\_key =\> 'owner\_id' &nbsp;&nbsp;&nbsp;&nbsp;has\_many :project\_viewers, :dependent =\> :destroy &nbsp;&nbsp;&nbsp;&nbsp;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!

---

<div class="post-metadata">

**Author:** ![Steve\_Ross](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@Steve\_Ross](https://discuss.rubyonrails.org/u/Steve_Ross)\
**Post date:** [November 26, 2006, 10:44pm UTC](https://discuss.rubyonrails.org/t/associations-help/5053/3 "2006-11-26T22:44:49Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![Craig\_White2](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@Craig\_White2](https://discuss.rubyonrails.org/u/Craig_White2)\
**Post date:** [November 26, 2006, 10:54pm UTC](https://discuss.rubyonrails.org/t/associations-help/5053/4 "2006-11-26T22:54:48Z")

</div>

Nope - ignore me and my stupid suggestion.

😉

Craig
