dbix-class

Retrieving data from a has_many relationship in DBIx::Class.

Given a simple case of two tables - Term and Definition - where Term has_many Definitions and Definition belongs_to Term, all terms and the corresponding definitions are to be fetched and displayed somehow. Here is what I've come up with so far: my $terms= $schema->resultset('Term')->search(undef, { prefetch => 'definitions', }...

How can I model an is-a relationship with DBIx::Class?

With the following (simplified) MySQL table definitions: create table items ( item_id int unsigned auto_increment primary key, purchase_date date ) engine = innodb; create table computers ( item_id int unsigned primary key, processor_type varchar(50), foreign key item_fk (item_id) references i...

How do I do this search and order_by on a DBIx::Class::ResultSet

Problem definition. I have multiple clients with multiple users. Each client needs to be able to associate custom data with a user, search, and order by. Database Solution: A table Customfields which defines the customfields table. It has an id and name. It has a has_many relationship with a Userfields table (aka "attributes"). The...

How to count the number of queries with DBIx::Class ?

I'm using DBIx::Class in a web context and I'd like to display the number of SQL queries performed and the time they took for the rendering of a page. Any idea about how to implement that? ...

Queries to get all ancestors/descendents of a tree in a db?

I have a table (id, parent_id, data) where parent_id points to another row in same table (or is null). Is there a standard way to query (1) all the ancestors of a certain id and (2) all the descendants of a certain id? I'm also doing this in DBIx::Class, so if there's a most convenient way to do it with that module (or some other), I'd...

groups of groups using self joins in DBIx::Class

I'm trying to understand how to use DBIx::Class. If I want groups of records such that groups can themselves be members of groups, I might create a schema that includes something like this: CREATE TABLE groups ( id INTEGER PRIMARY KEY, name VARCHAR(100) ); CREATE TABLE group_groups ( parent_id I...

Why does DBIx::Class with multiple inheritance fail on update?

I have a DBIC schema, where all the classes use a common base class, and definition class. The base class loads common components, and overrides the update method in order to record changesets in an audit table. The definition class is a static class generated from the database. A typical class header looks something like: package Schem...

How do I figure out what module is loading Moose?

I am trying to figure out which module in my CGI::Application is loading Moose. I attempted to overload "require" but I don't seem to have the syntax quite right. If someone could clean up the following code I would appreciate it: use strict; use warnings; use Carp qw//; BEGIN { *CORE::GLOBAL::require = sub (*) { warn "Requiring...

Does DBIx::Class::Schema::Loader cache its moniker map?

Recently we added a "audit_logs" table to the database, and after some frustration I realised that there was already an "auditlog" table in the database for some reason. It wasn't being used so I dropped it. I deleted the Auditlog.pm and AuditLogs.pm files from my schema, and then regenerated. For some reason DCSL again created AuditLogs...

How can I pretty print DBIx::Class results?

I'd like to pretty-print DBIx::Class::ResultSet results like this: my $schema = MyDatabase::Main->connect('dbi:SQLite:db/example.db'); my $rs = $schema->resultset('Track')->all() # then print $rs with all of those feilds I found DBIx::SQLCrosstab::Format class but it seems to work only with own queries. ...

Setting up a Many-to-Many relation of a table with itself with DBIx::Class

I am porting an application from Class::DBI to DBIx::Class and need help. I have a table T with a primary key tid and another table ChildT that relates a row of T to multiple (child) rows of T itself. How can I setup the relations between T and ChildT so that I can find all children of an instance of T. Here are the stripped down version...