0

Could someone explain in which cases I have to use create or populate methods on ResultSet in DBIx::Class? And what differences between each other if everyone is used to insert some data to database?

UPD For example. I have to insert some data to table1. There are create and populate methods for it. So I have to use create if there are any relationships otherwise I have to use populate, aren't there?

edem
  • 3,222
  • 3
  • 19
  • 45

2 Answers2

2

Create inserts one row (and possibly associated rows in other tables). Populate inserts multiple rows.

hobbs
  • 223,387
  • 19
  • 210
  • 288
  • are multiple rows inserted only in one table? Could you give some examples to illustrate it? – edem Mar 19 '13 at 20:09
  • you can use DBIC_TRACE and see an example yourself – ugexe Mar 19 '13 at 20:37
  • The DBIx::Class reference docs for populate have examples: https://metacpan.org/module/DBIx::Class::ResultSet#populate – Alexander Hartmaier Mar 19 '13 at 21:56
  • @abraxxa I read docs and mans about it but I want to see how these two methods are distinguished by the example. Try to explain what I want. I have to insert some data to table1. There are `create` and `populate` methods for it. So I have to use `create` if there are any relationships otherwise I have to use `populate`, aren't there? – edem Mar 19 '13 at 23:12
  • @edem no, no, no. It's not nearly that complicated. You use `create` to insert one thing into table1. You use `populate` to insert multiple things. – hobbs Mar 19 '13 at 23:57
0

as added information and a precaution:

insert always works ( and usually as expected ). You can use it for inserting many tables, the issue is performance.

When inserting a large amount of data, populate is much faster. It does, however, sometimes behave strangely, so you should test it carefully ( as everything ;) ). Normally, it works fine, though, and when you insert thousands of entries, you will notice a significant increase in speed.