Since mst has been questioning my sanity, I thought I'd verify this:

With CDBI I might have a FormToken class where I could get a new token
using this class method:

    my $token = FormToken->new_token;


With DBIC I'm using ResultSetManager.  In my ResultSource / table
class I have:

    sub new_token : ResultSet {
        my $rs = shift;

        return $rs->create( { id => Data::UUID->new->create_str } );
    }

And then I call $schema->resultset('FormToken')->new_token;

Is that the correct and recommend approach?


Second, I thought I saw in the docs how to do update with a where
clause.   So, another example with the FormToken class.  Say I have a
$token and I want to invalidate it, but only if it's currently valid.

sub invalidate {
    my $token = shift;

    my $dbh = $token->result_source->schema->storage->dbh;

    my $sth = $dbh->prepare_cached( << '' );
        UPDATE form_token SET valid = FALSE WHERE id = ? AND valid = TRUE

    $sth->execute( $token->id );
    return $sth->rows;
}

What's the DBIC way to do that?


Thanks,


-- 
Bill Moseley
[EMAIL PROTECTED]


_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/

Reply via email to