[Dbix-class] "Deletion" of records by setting status to 'deleted'

Bob MacCallum uncoolbob at gmail.com
Tue Mar 10 09:26:27 GMT 2015


I am not an expert, but shouldn't it just work with

__PACKAGE__->resultset_attributes({ where => { status => { '!=' =>
'deleted' } } });


?

However, I've only ever used order_by in resultset_attributes so YMMV.



On Mon, Mar 9, 2015 at 6:04 PM, Ilya Chesnokov <chesnokov.ilya at gmail.com>
wrote:

> Hi,
>
> I have a "service" table in my database and want to mark services as
> deleted by setting service.status = 'deleted' instead of actually
> deleting them (for business reasons).
>
> I do it in a working project where DBIC is used as a database
> interaction layer, and it is preferable to make these changes as
> transparent  to the surrounding code as possible. Our codebase is
> (mostly) covered with tests, so it's generally easy to understand
> whether there is a regression or not.
>
> First I tried to override search_rs() method in a custom resultset
> with something like this:
> https://gist.github.com/ichesnokov/1d4236f79c69fd14ebbe, but it didn't
> work as expected on prefetches with condition in them.
>
> Then I tried a method with resultset_attributes (see
> https://metacpan.org/pod/DBIx::Class::ResultSource#resultset_attributes),
> but it didn't work because it's impossible to get
> "current_source_alias" from ResultSource.
>
> Currently I'm using something based on the behavior of
> resultset_attributes (see
> https://gist.github.com/ichesnokov/e5fb7e70cb6d497ea5a0), and it
> works, but requires fiddling with internal state of a resultset, which
> seems a bit wrong.
>
> Is there any better way for achieving the same?
>
> Thanks.
> --
> Best regards,
> Ilya Chesnokov
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive:
> http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20150310/a363bcc0/attachment.htm>


More information about the DBIx-Class mailing list