On Wed, 10 Jan 2007, Octavian Rasnita wrote:

Hi,

Is it possible to insert more records using the same code and just adding a certain different field for each record?

I wanted to do something like:

my $rs = $schema->resultset("Table")->new({
# here some more fields defined
});

This produces a Table object, not a resultset, see the DBIx::Class::ResultSet docs:

       IMPORTANT: If called on an object, proxies to new_result instead so

         my $cd = $schema->resultset('CD')->new({ title => 'Spoon' });

       will return a CD object, not a ResultSet.


foreach my $user(@users) {
$rs->user($user);
}

$rs->insert;

If all you are doing is creating new rows, and throwing away the objects, then you could just use populate() instead:

$schema->populate('Table', [
                  [ 'user' ],          # list of field names
                  ['username1'],       # values for the fields
                  ['username2'],       # values for another row
                 ]);

This code inserts just the first record corresponding to the first element of @users.

Do I need to create a new $rs for each element of @users?

No, you could also just empty the PK cols and unset in_storage(), but populate is the correct way to do this.


Jess


_______________________________________________
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]/

Reply via email to