I was crying about this on IRC this afternoon, but didn't get much of a
response, i've bashed away at it long enough to come up with a failing
test now, so maybe someone can help me out.
the attached files go like this.
t/adam_test.t
t/lib/EatLocal/DB.pm
t/lib/EatLocal/DB/Object.pm
t/lib/EatLocal/DB/User.pm
then you can run
RDBO_MYSQL_PASS=root_mysql_password prove t/adam_test.t
and watch the middle test fail. I was running this against the version
from svn.
in a nutshell, when i do this:
my $o1 = EatLocal::DB::User->new(user_name => 'adam');
ok($o1->load(speculative => 1), "unique key load 1 - user_name");
my $o2 = EatLocal::DB::User->new(email => '[EMAIL PROTECTED]');
ok($o2->load(speculative => 1), "unique key load 2 - email");
i get (wrong):
SELECT user_id, user_name, fname, lname, email, pass_hash, location_id,
created_date, modified_date, activated, admin FROM users WHERE email = ?
- bind params:
and (right)
SELECT user_id, user_name, fname, lname, email, pass_hash, location_id,
created_date, modified_date, activated, admin FROM users WHERE email = ?
- bind params: [EMAIL PROTECTED]
respectively.
as far as i can tell, unique_keys is setup right (it's exactly what i
got out of Loader, but with the foreign keys and relationships removed
for the test)
unique_keys => [
[ 'email' ],
[ 'user_name' ],
],
any help would be appreciated. I'm going to go look at the code now
myself and see if i can come up with anything.
Adam
#!/usr/bin/perl -w
use strict;
use Test::More tests => 1 + 2;
use lib qw(./t/lib);
BEGIN
{
require 't/test-lib.pl';
use_ok('EatLocal::DB::User');
}
our %Have;
my $count = 1;
#
# Tests
#
#$Rose::DB::Object::Debug = 1;
my $o1 = EatLocal::DB::User->new(user_name => 'adam');
ok($o1->load(speculative => 1), "unique key load 1 - user_name");
my $o2 = EatLocal::DB::User->new(email => '[EMAIL PROTECTED]');
ok($o2->load(speculative => 1), "unique key load 2 - email");
BEGIN
{
our %Have;
my $dbh;
#
# MySQL
#
eval
{
my $db = Rose::DB->new('mysql_admin');
$dbh = $db->retain_dbh or die Rose::DB->error;
# Drop existing tables, ignoring errors
{
local $dbh->{'RaiseError'} = 0;
local $dbh->{'PrintError'} = 0;
$dbh->do('DROP TABLE rose_db_object_uk_test');
}
};
if(!$@ && $dbh)
{
$Have{'mysql'} = 1;
$dbh->do(<<"EOF");
CREATE TABLE `users` (
`user_id` int(10) unsigned NOT NULL auto_increment,
`user_name` varchar(50) NOT NULL default '',
`fname` varchar(100) NOT NULL default '',
`lname` varchar(100) NOT NULL default '',
`email` varchar(50) NOT NULL default '',
`pass_hash` varchar(50) NOT NULL default '',
`location_id` int(10) unsigned NOT NULL default '0',
`created_date` timestamp NOT NULL default '0000-00-00 00:00:00',
`modified_date` timestamp NOT NULL default CURRENT_TIMESTAMP
on update CURRENT_TIMESTAMP,
`activated` tinyint(1) NOT NULL default '0',
`admin` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`user_id`),
UNIQUE KEY `user_name` (`user_name`),
UNIQUE KEY `email` (`email`),
KEY `location_id` (`location_id`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8
EOF
$dbh->do(<<"EOF");
INSERT INTO `users` VALUES
(1,'adam','Adam','Prime','[EMAIL PROTECTED]','ddd',1,'2006-12-28
06:14:05','2007-08-06 22:35:32',1,1)
EOF
$dbh->disconnect;
}
}
END
{
# Delete test table
if($Have{'mysql'})
{
# MySQL
my $dbh = Rose::DB->new('mysql_admin')->retain_dbh()
or die Rose::DB->error;
$dbh->do('DROP TABLE users');
$dbh->disconnect;
}
}
package EatLocal::DB;
use Rose::DB;
our @ISA = qw(Rose::DB);
__PACKAGE__->use_private_registry;
__PACKAGE__->register_db(
#domain => 'default',
#type => 'main',
driver => 'mysql',
database => 'test',
host => 'localhost',
username => 'root',
password => $ENV{'RDBO_MYSQL_PASS'},
);
__PACKAGE__->register_db(
domain => 'test',
type => 'mysql',
driver => 'mysql',
database => 'test',
host => 'localhost',
username => 'root',
password => $ENV{'RDBO_MYSQL_PASS'},
);
1;
package EatLocal::DB::Object;
use Rose::DB::Object;
our @ISA = qw(Rose::DB::Object);
use EatLocal::DB;
sub init_db { EatLocal::DB->new }
1;
package EatLocal::DB::User;
use strict;
use base qw(EatLocal::DB::Object);
__PACKAGE__->meta->setup(
table => 'users',
columns => [
user_id => { type => 'integer', not_null => 1 },
user_name => { type => 'varchar', default => '', length => 50,
not_null => 1 },
fname => { type => 'varchar', default => '', length => 100,
not_null => 1 },
lname => { type => 'varchar', default => '', length => 100,
not_null => 1 },
email => { type => 'varchar', default => '', length => 50,
not_null => 1 },
pass_hash => { type => 'varchar', default => '', length => 50,
not_null => 1 },
location_id => { type => 'integer', default => '0', not_null => 1 },
created_date => { type => 'timestamp', not_null => 1 },
modified_date => { type => 'timestamp', not_null => 1 },
activated => { type => 'integer', default => '0', not_null => 1 },
admin => { type => 'integer', default => '0', not_null => 1 },
],
primary_key_columns => [ 'user_id' ],
unique_keys => [
[ 'email' ],
[ 'user_name' ],
],
);
1;
-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object