[Dbix-class] load_classes and common base class
    Bill Moseley 
    moseley at hank.org
       
    Sat Apr 21 16:06:16 GMT 2007
    
    
  
On Sat, Apr 21, 2007 at 03:19:14PM +0100, Ash Berlin wrote:
> The way I do things is;
Ok, so your result sources just inherit from a base class.
Ok, so this has me wondering:
>     # $self->resultset_class('My::ResultSet');
I noticed that in the cookbook.  Are you using a single class to
define commonly used result sets?  Seems like one would want custom
result sets to be specific to a given table class.
Where is resultset_class documented?
I think an example would help clear things up for me quite a bit:
In CDBI I create extra methods in the table classes as needed to
extend those classes.  Sometimes these are instance methods and other
times class methods.
For example, I have the common setup where when someone signs up for
an account they get sent a confirmation email that they must use to
complete the registration process.
I have a table account_confirmation that tracks these pending accounts.
I also have a users table (called "person") where I store their signup
data.
People will sign up for an account, but never complete the process by
responding to the account confirmation email, so I have to
periodically delete those pending accounts.
In CDBI I have a class methods that does that:
    App::AccountConfirmation->clean;
And a feature (or problem) with CDBI is that the $dbh can be found
from the class using Foo->db_Main.  Don't need to pass $schema in, for
example.
That means I can do:
package AccountConfirmation;
sub clean {
    my $self = shift;
    # Deleting a person will cascade delete account_confirmation
    my $sql = <<'';
        delete from person where id in
        (
            SELECT
                p.id
            FROM
                person p
                JOIN account_confirmation a ON (p.id = a.person)
            WHERE
                a.created_time < now() - interval '1 day'
        )
    return $self->db_Main->do( $sql );
}
So, how do I implement something like that in DBIC?
Is this where ResultSetManager comes in?
-- 
Bill Moseley
moseley at hank.org
    
    
More information about the Dbix-class
mailing list