# Associations, named\_scope, and "active" records

**URL:** <https://www.ruby-forum.com/t/associations-named-scope-and-active-records/165634>\
**Category:** Rails\
**Created:** [April 15, 2009, 10:58pm UTC](https://www.ruby-forum.com/t/associations-named-scope-and-active-records/165634 "2009-04-15T22:58:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrpunkin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@mrpunkin](https://www.ruby-forum.com/u/mrpunkin)\
**Post date:** [April 15, 2009, 10:58pm UTC](https://www.ruby-forum.com/t/associations-named-scope-and-active-records/165634/1 "2009-04-15T22:58:53Z")

</div>

Hello all,

We are converting our application so that user-generated content such as  
votes, photos, users, comments, etc are all disabled instead of deleted.  
This serves us better as administrators of the site as well as fits into  
a UI redesign coming later that will include undo functionality. The  
question I have is would it be better to place the active=true condition  
part of all my associations I already have in place (little work), or do  
I strip my associations down to barebones and build named\_scopes for my  
“active” state, and any other states? The problem here is I would need  
to append nearly all calls to photo.votes, photo.comments,  
project.photos, project.votes, etc with .active (much more work).

Which is the better method in the long run? Thanks guys.

---

<div class="post-metadata">

**Author:** ![mrpunkin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@mrpunkin](https://www.ruby-forum.com/u/mrpunkin)\
**Post date:** [April 15, 2009, 11:39pm UTC](https://www.ruby-forum.com/t/associations-named-scope-and-active-records/165634/2 "2009-04-15T23:39:02Z")

</div>

Makes sense just to add conditions to the associations

so:  
class Photo  
has\_many :votes, :conditions =\> ['active = ? ', true]  
end

I presume this is what you’re planning on doing at the moment?

Less work and I doubt the scope would perform noticeably better (if at  
all) ?

Why not try both methods and check the speed of each query?

On Apr 15, 9:58 pm, Bryan C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![mrpunkin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@mrpunkin](https://www.ruby-forum.com/u/mrpunkin)\
**Post date:** [April 18, 2009, 11:39pm UTC](https://www.ruby-forum.com/t/associations-named-scope-and-active-records/165634/3 "2009-04-18T23:39:45Z")

</div>

I’d suggest that you take a look at acts\_as\_paranoid for some ideas to  
implement this without scattering checks all over the application.  
Also dig around for a discussion on re-implementing acts\_as\_paranoid  
with default\_scope.

–Matt J.

On Apr 15, 4:58 pm, Bryan C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
