Re: [Dbix-class] Duplication of records in many-to-many prefetch

2013-05-02 Thread Shea Levy
On 05/02/2013 02:25 AM, Peter Rabbitson wrote: On Wed, May 01, 2013 at 06:16:57PM -0400, Shea Levy wrote: Hi all, In my project, a user can have multiple roles and multiple users can have the same role. The username is the primary key for the users table. When I run a query like: ->search({ 'm

Re: [Dbix-class] How to build a "good" object with deep nested prefetched rows from raw data?

2013-05-02 Thread Peter Rabbitson
On Thu, May 02, 2013 at 03:08:18PM +0400, Dmitry L. wrote: > Peter, thanks! > > Right now I use a wrapper around ResultSet->all and set_cache for childs. > And in code I retrieve all data at once via ->all. Right, and and as you noticed this is suboptimal ;) The feature in question (allow a rand

Re: [Dbix-class] How to build a "good" object with deep nested prefetched rows from raw data?

2013-05-02 Thread Dmitry L.
Actually categories - it was just an example. In my project I use a stored procedures in DB with recursive queries and complex logic. So just using DBIC is a little bit hard in my case. And problem is a building a DBIC object with using a predefined data. On 2 May 2013 14:57, Oleg Kostyuk wrote:

Re: [Dbix-class] How to build a "good" object with deep nested prefetched rows from raw data?

2013-05-02 Thread Dmitry L.
Peter, thanks! Right now I use a wrapper around ResultSet->all and set_cache for childs. And in code I retrieve all data at once via ->all. On 2 May 2013 15:01, Peter Rabbitson wrote: > On Thu, May 02, 2013 at 08:57:30PM +1000, Peter Rabbitson wrote: > > > > *) Allow {cursor} to be set (either

Re: [Dbix-class] How to build a "good" object with deep nested prefetched rows from raw data?

2013-05-02 Thread Peter Rabbitson
On Thu, May 02, 2013 at 01:57:54PM +0300, Oleg Kostyuk wrote: > There are already several ready to use solutions to > store hierarchical structures in database - why do you want to reinvent the > wheel? Because they have an already-existing schema, with a local wheel invented ages ago, and are ju

Re: [Dbix-class] How to build a "good" object with deep nested prefetched rows from raw data?

2013-05-02 Thread Peter Rabbitson
On Thu, May 02, 2013 at 08:57:30PM +1000, Peter Rabbitson wrote: > > *) Allow {cursor} to be set (either via cursor() or make a separate setter) > *) Make it accept a coderef > *) Teach all()/next()/single() to pre-populate {_stashed_rows} > *) Make _construct_results() aware of this somehow (hand

Re: [Dbix-class] How to build a "good" object with deep nested prefetched rows from raw data?

2013-05-02 Thread Oleg Kostyuk
There are already several ready to use solutions to store hierarchical structures in database - why do you want to reinvent the wheel? http://search.cpan.org/dist/DBIx-Class-Tree/ http://search.cpan.org/dist/DBIx-Class-Tree-Mobius/ http://search.cpan.org/dist/DBIx-Class-Tree-NestedSet/ 20

Re: [Dbix-class] How to build a "good" object with deep nested prefetched rows from raw data?

2013-05-02 Thread Peter Rabbitson
On Thu, May 02, 2013 at 01:39:24PM +0400, Dmitry L. wrote: > > QUESTION > How can I convert raw data, which could be returned by calling > category_descendants($id), to a "good" DBIx::Class object? > I want to call category_descendants($id), and then I want to use something > like this: > $rs->firs

Re: [Dbix-class] Returning search results in a specific order

2013-05-02 Thread Will Crawford
On 30 April 2013 19:21, Chris Newman wrote: > I have a search like this: > > my $ids = [2, 1, 3]; > > $schema->resultset (‘MyTable’)->search (id => $ids); > > > > MySQL processes rows in the order they are found in the table so I > essentially get back 1, 2, 3. $ids is really a user-specified li

Re: [Dbix-class] Returning search results in a specific order

2013-05-02 Thread QE :: Felix Ostmann
W ​e gene​rate a special ORDER BY for such a scenario (that should work for most RDBMs): ORDER BY id = 2 ASC, id = 1 ASC, id = 3 ASC 2013/5/1 Peter Rabbitson > On Tue, Apr 30, 2013 at 08:36:50PM +, Chris Newman wrote: > > > From: Peter Rabbitson [mailto:rabbit+d...@rabbit.us] > > Sent:

[Dbix-class] How to build a "good" object with deep nested prefetched rows from raw data?

2013-05-02 Thread Dmitry L.
Hello! OVERVIEW Imagine that we have some data in DB, which can be represented in nested structure Eg. categories tree: CREATE TABLE categories ( id INT NOT NULL, parent_id INT NULL , title TEXT, CONSTRAINT "subcategories" FOREIGN KEY("parent_id") REFERENCES "categories"("id") );