Hello!

A little overview.
I have 1 table (users), and 3 result classes: AbstractUser, User and Admin.

Table has column role (which defines who user is - Admin or User). And I use 
inflate_result in AbstractUser result class to "transform" it to Admin or User.

I want to call $schema->resultset('Admin')->search->all to retrieve all admins 
from 
table 'users' (...WHERE role = 'ADMIN'). And the same for users (to retrieve 
users).

So I created ResultSet class for AbstractUser. Also ResultSets for User and 
Admin 
(which are inherited from ResultSet::AbstractUser) are created too.

In  ResultSet::AbstractUser I overwrite search method and added accessor role.
Here in search method I add $self->current_source_alias .'.role' = $self->role 
to 
search condition. And then call next::method.

In ResultSet::Admin and ResultSet::User I overwrite search method to set role 
accessor only and calling next::method.

It seems that search works. But I got "user.role" condition twice.:

SELECT user.id, user.name, user.role FROM admin_users me  JOIN users user ON 
user.id = me.user_id WHERE ( ( user.role = ? AND ( user.role = ? AND 
me.admin_id 
= ? ) ) ): 'USER', 'USER', '1'



The next.
When I try $admin->add_to_user({...}), I got the error. So the error is that 
current_source_alias 'me' and current_source_alias is 'user' at the same time:

$admin->add_to_users( { name => 'User #1', role => 'USER', } );
=====>
SELECT user.id, user.name, user.role FROM users user WHERE ( ( ( user.name = ? 
AND user.role = ? ) AND me.role = ? ) ): 'User #1', 'USER', 'USER'

Where am I wrong?
Or is there easier method to do the same?

Thank you!

PS: example is here http://kino.dim0xff.com/dbx/db_test.tar.gz

-- 
//wbr, Dmitry L.
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk

Reply via email to