Forum: Ruby on Rails Deactivate instances on delete

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8bb6af7547c07a6d41e5f82515f59a83?d=identicon&s=25 lundie (Guest)
on 2007-07-30 19:59
(Received via mailing list)
Hi,

I have created an application in which a customer model has many
locations. Customers are then assigned to an order, and one of their
locations is also assigned to the order.

My issue comes if a locations is removed from the customer, that was
assigned to an order.  I have added an active field to the locations
table, and when I "delete" the location, it sets it to false.

My question is how to do the find statements correctly. Should I be
overwriting the find method within the locations model to only return
active locations? Then if I do that, and the order.location method is
called, how do I get it to return the old location that is not active.

Am I going about this the right way or is there a more efficient way
to handle it?
391f9b787cdc12aa2c179713f5103e3a?d=identicon&s=25 Ilan Berci (iberci)
on 2007-07-30 23:01
lundie wrote:
> Hi,
>
> I have created an application in which a customer model has many
> locations. Customers are then assigned to an order, and one of their
> locations is also assigned to the order.
>
> My issue comes if a locations is removed from the customer, that was
> assigned to an order.  I have added an active field to the locations
> table, and when I "delete" the location, it sets it to false.
>
> My question is how to do the find statements correctly. Should I be
> overwriting the find method within the locations model to only return
> active locations? Then if I do that, and the order.location method is
> called, how do I get it to return the old location that is not active.
>
> Am I going about this the right way or is there a more efficient way
> to handle it?

I don't see why you need to override anything, if you only are
interested in active locations then you can always add that requirement
to your find conditions.  In this way, you will not impact your Order
processing at all as it can still contain "deleted" addresses.

hth

ilan
821395fe70906c8290df7f18ac4ac6cf?d=identicon&s=25 Rick Olson (Guest)
on 2007-07-30 23:57
(Received via mailing list)
On 7/30/07, lundie <rlundie@gmail.com> wrote:
>
> My question is how to do the find statements correctly. Should I be
> overwriting the find method within the locations model to only return
> active locations? Then if I do that, and the order.location method is
> called, how do I get it to return the old location that is not active.
>
> Am I going about this the right way or is there a more efficient way
> to handle it?

I have an old acts_as_paranoid plugin that does this.  It overrides
#destroy and tries to override #find so that the use of the deleted_at
field is transparent.  Problem is, it tends to break down in certain
edge cases.  I recommend you keep it a little more explicit and use
the scope_out plugin.

http://svn.techno-weenie.net/projects/plugins/acts...
http://code.google.com/p/scope-out-rails/

--
Rick Olson
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com
8bb6af7547c07a6d41e5f82515f59a83?d=identicon&s=25 lundie (Guest)
on 2007-07-31 15:12
(Received via mailing list)
Thanks!

scope-out looks like it will do the trick.
This topic is locked and can not be replied to.