Skip Menu |

This queue is for tickets about the Catalyst-Controller-DBIC-API CPAN distribution.

Report information
The Basics
Id: 60768
Status: stalled
Worked: 10 min
Priority: 0/
Queue: Catalyst-Controller-DBIC-API

People
Owner: abraxxa [...] cpan.org
Requestors: jgentle [...] safeschools.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Unable to handle multiple primary keys
Date: Thu, 26 Aug 2010 12:21:16 -0400
To: bug-Catalyst-Controller-DBIC-API [...] rt.cpan.org
From: Jon Gentle <jgentle [...] safeschools.com>
We are working on using DBIC::API to create a REST API, and we have a couple tables that have a multiple column primary key. The data is completely inaccessible from the DBIC::API since a single column primary key is assumed. I have worked around the problem by making a quick and dirty patch to object_lookup (below), but I doubt that is the proper solution. The version that is installed is 2.002001. Thanks. -Jon Gentle --- --- a/lib/perl5/Catalyst/Controller/DBIC/API.pm +++ b/lib/perl5/Catalyst/Controller/DBIC/API.pm @@ -210,7 +210,8 @@ sub object_lookup my ($self, $c, $id) = @_; die 'No valid ID provided for look up' unless defined $id and length $id; - my $object = $c->req->current_result_set->find($id); + my @id = split /::/, $id; + my $object = $c->req->current_result_set->find(@id); die "No object found for id '$id'" unless defined $object; return $object; }
There is no general solution to this problem which could be added to dbic::api as far as I can think because you never know how many pk's a result object has and which character to use to split them. I have the same situation for one table where I've overridden object_lookup to do what I want. I've chosen the @ char as join character because it isn't a valid character in the two columns that form the pk. Because I need the lookup using the @ char more often I've added a method to the ResultSet class of this table which does the splitting and find. Another possibility would be to change the object url completely by overriding object_with_id. e.g.: /api/rest/foo/col1/$key1/col2/$key2 It would be great if you submit a doc patch that shows the solution you've chosen for multi-pk lookups!
Deferred until you come up with a patch and tests.