# Acts\_as\_paranoid and Association Extensions (has\_one trouble

**URL:** <https://www.ruby-forum.com/t/acts-as-paranoid-and-association-extensions-has-one-trouble/111218>\
**Category:** Rails\
**Created:** [August 3, 2007, 10:13pm UTC](https://www.ruby-forum.com/t/acts-as-paranoid-and-association-extensions-has-one-trouble/111218 "2007-08-03T22:13:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ea666f/32.png) [@bob](https://www.ruby-forum.com/u/bob)\
**Post date:** [August 3, 2007, 10:13pm UTC](https://www.ruby-forum.com/t/acts-as-paranoid-and-association-extensions-has-one-trouble/111218/1 "2007-08-03T22:13:59Z")

</div>

Hi… Isn’t there a proper way or hack/workaround for the following?

- For the example with unfortunate disabilities… look below,  
Usage of has\_\* (associationmethods) do {def with\_deleted  
AccociatedModel#with\_scope} {Paranoid’s#find\_with\_deleted}…  
The has\_one associations give me a nil object when invoking it with  
Model.association\_OBJECT.with\_deleted. Has\_many does like expected:  
Model.association\_COLLECTION.with\_deleted.

- Example:  
The disability of my approach you see below after the lines with  
########### signs…  
First on to: class Organization

class Organization \< ActiveRecord::Base  
acts\_as\_paranoid

has\_one :contact\_address, :as =\> :addressable, :dependent  
=\> :destroy do  
def with\_deleted  
ContactAddress.with\_scope(:find =\> {:conditions =\>  
“addressable\_id = #{proxy\_owner.id}”}) do  
find\_with\_deleted(:all)  
end  
end  
end

Loading development environment.

> > sc = SportClub.find\_with\_deleted(7)  
> > =\> #\<SportClub:0xb769c1a4 @attributes={“number\_of\_members”=\>nil,  
> > “name”=\>“Maastricht Wildcats”, “updated\_at”=\>“2007-08-03 21:50:44”,  
> > “deleted\_at”=\>nil, “created\_by”=\>nil, “organization\_code”=\>“KNVB347”,  
> > “url”=\>nil, “type”=\>“SportClub”, “updated\_by”=\>nil, “id”=\>“7”,  
> > “description”=\>"", “deleted\_by”=\>nil, “created\_at”=\>nil}\>

> > sc.destroy  
> > =\> #\<SportClub:0xb769c1a4 @sportables\_sports=[], @deleted\_by=nil,  
> > @contact\_address=, @new\_record\_before\_save=nil, @events=[],  
> > @attributes={“number\_of\_members”=\>nil, “name”=\>“Maastricht Wildcats”,  
> > “updated\_at”=\>“2007-08-03 21:50:44”, “deleted\_at”=\>nil,  
> > “created\_by”=\>nil, “organization\_code”=\>“KNVB347”, “url”=\>nil,  
> > “type”=\>“SportClub”, “updated\_by”=\>nil, “id”=\>“7”, “description”=\>"",  
> > “deleted\_by”=\>nil, “created\_at”=\>nil}, @geographic=,  
> > @accommodations=[],  
> > @organizations\_target\_groups=[#\<OrganizationsTargetGroup:0xb76c2908  
> > @deleted\_by=nil, @attributes={“updated\_at”=\>“2007-08-03 21:50:44”,  
> > “target\_group\_id”=\>“2”, “deleted\_at”=\>nil, “created\_by”=\>nil,  
> > “updated\_by”=\>nil, “id”=\>“1”, “deleted\_by”=\>nil,  
> > “organization\_id”=\>“7”, “created\_at”=\>“2007-08-03 09:56:08”}\>],  
> > @site\_addresses=[]\>

> > sc = SportClub.find\_with\_deleted(7)  
> > =\> #\<SportClub:0xb769889c @attributes={“number\_of\_members”=\>nil,  
> > “name”=\>“Maastricht Wildcats”, “updated\_at”=\>“2007-08-03 21:50:44”,  
> > “deleted\_at”=\>“2007-08-03 22:03:12”, “created\_by”=\>nil,  
> > “organization\_code”=\>“KNVB347”, “url”=\>nil, “type”=\>“SportClub”,  
> > “updated\_by”=\>nil, “id”=\>“7”, “description”=\>"", “deleted\_by”=\>nil,  
> > “created\_at”=\>nil}\>

#################################  
Please tell me whyyyyy… isn’t there any way???  
#################################

> > sc.contact\_address.with\_deleted  
> > NoMethodError: You have a nil object when you didn’t expect it!  
> > The error occurred while evaluating nil.with\_deleted  
> > from (irb):4

> > sc.organizations\_target\_groups.with\_deleted  
> > =\> [#\<OrganizationsTargetGroup:0xb7603814  
> > @attributes={“updated\_at”=\>“2007-08-03 21:50:44”,  
> > “target\_group\_id”=\>“2”, “deleted\_at”=\>“2007-08-03 22:03:12”,  
> > “created\_by”=\>nil, “updated\_by”=\>nil, “id”=\>“1”, “deleted\_by”=\>nil,  
> > “organization\_id”=\>“7”, “created\_at”=\>“2007-08-03 09:56:08”}\>]
