Ok, thank you for this example.
Octavian
----- Original Message -----
From: "Fernan Aguero" <[EMAIL PROTECTED]>
To: "Octavian Rasnita" <[EMAIL PROTECTED]>
Cc: <[email protected]>
Sent: Tuesday, January 09, 2007 10:07 PM
Subject: Re: [Dbix-class] adding conditions
+----[ Octavian Rasnita <[EMAIL PROTECTED]> (09.Jan.2007 16:20):
|
| From: "Oliver Gorwits" <[EMAIL PROTECTED]>
|
| >>How can I add these conditions after defining $rs?
| >
| >$rs = $rs->search({id_user => $id_user});
|
| Thank you. This way it works well. I have tried:
|
| $rs->{cond}->{id_user} = $id_user;
|
| And it works, but only when some conditions are previously defined.
|
+----]
I don't know if $rs->{cond} is an internal structure. If it
is, you don't want to mess with it.
But I guess I know where you're trying to go ...
Do notice that the first element passed to $rs->search
is a hashref. You can build this hash or hashref yourself
along the way (for example while parsing some input file)
and then submit the conditions to your search.
If you also build your search attributes into a separate
structure, this also makes for a shorter (and easier to
read) call to ->search().
my %where;
$where{user_id} = 1;
$where{name} = { 'like', '%fernan%' };
$where{lastname} = { '!=', 'Rasnita' };
$where{weight} = { '<=', '100' };
my %attributes;
$attributes{order_by} = 'weight DESC';
$attributes{distinct} = 1;
$attributes{columns} = [ qw/ user_id name / ];
my $rs = $model->search( \%where, \%attributes );
Fernan
PS: I like to use %where for this in my code, cause
it makes it clear that everything you put there will be
part of the SQL WHERE clause.
_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/