[Dbix-class] Newbie question about relations

Diego M. Vadell dvadell at linuxclusters.com.ar
Tue Oct 17 06:18:44 CEST 2006


Hi,
  I am just starting with DBIx::Class and Catalyst, and quite frankly I don't 
know much about designing the tables. I decided to start exploring Catalyst 
by making a simple file server via web, with sqlite tables:

CREATE TABLE Files (
            id          INTEGER PRIMARY KEY,
            filename       TEXT
    );

    CREATE TABLE Perms (
            file_id     INTEGER,
            user_id     INTEGER,
            read        BOOLEAN,
            del         BOOLEAN,
            new         BOOLEAN,
            PRIMARY KEY (file_id, user_id)
    );
    CREATE TABLE Users (
            id          INTEGER PRIMARY KEY,
            username    TEXT,
            password    TEXT
    );

The idea is that the "Files" tables has a filename, the "Users" have username 
and password and "Perms" have the ACL of every file wrt every user. I can 
$schema->populate Files and Users, but when I try to do it with Perms, I get:

Can't use string ("WFSDB::Perms") as a HASH ref while "strict refs" in use 
at /usr/lib/perl5/site_perl/5.8.5/DBIx/Class/InflateColumn.pm line 168.

This are the relationships:

------------
package WFSDB::Files;
#     3) Column name in *foreign* table
__PACKAGE__->has_many(file_perms => 'WFSDB::Perms', 'file_id');
__PACKAGE__->many_to_many(username => 'file_perms', 'users');

package WFSDB::Users;
__PACKAGE__->has_many(user_perms => 'WFSDB::Perms', 'user_id');
__PACKAGE__->many_to_many(files => 'user_perms', 'users');

package WFSDB::Perms;
__PACKAGE__->belongs_to(users => 'WFSDB::Users', 'user_id');
__PACKAGE__->belongs_to(files => 'WFSDB::Files', 'file_id');
-------------

The script I get the error with is:

---------
use WFSDB;
use strict;

my $schema = WFSDB->connect('dbi:SQLite:files.db');

my @perms = ( ["1", "1", "TRUE", "TRUE", "TRUE"], 
["1", "2", "TRUE", "TRUE", "TRUE"],
              ["2", "1", "FALSE", "FALSE", "FALSE"], 
["2", "2", "FALSE", "FALSE", "FALSE"] );

$schema->populate('Perms',[
    [qw/file_id user_id read del new/],
    @perms,
]);
----------

Can anybody help me with this? It smells like a basic, horrible, conceptual 
error, but I don't know how to fix it.

Thanks in advance,
 -- Diego.



More information about the Dbix-class mailing list