[Dbix-class] Dynamically removing an auto-increment column

Steve Bertrand steve at ibctech.ca
Tue Dec 8 20:29:05 GMT 2009


Dermot wrote:
> 2009/12/8 Steve Bertrand <steve at ibctech.ca>:
>> Hi everyone,
> 
> Hi Steve,
> 
>> I've just began using DBIx::Class late last week. Although I've got it
>> doing pretty well everything I want, I'm quite overwhelmed by the amount
>> of documentation, and hence, I'm having a hard time locating the
>> solution to a specific issue.
>>
>> In normal mode, my software uses a MySQL Replicated setup, which is all
>> well and good. In test mode, I use a Schema attached to an SQLite db.
>>
>> All reads work ok when switching back and forth, however any attempt to
>> write break.
>>
>> For MySQL, I have to have the 'id' field populated with a null value
>> when calling create(), and with SQLite, I have to remove the id field
>> (auto incr).
>>
>> Instead of writing if/else code in all of the methods that do an insert
>> to either include or exclude the id field, can someone advise on which
>> docs I need to read to be able to dynamically remove the id field from
>> the data I want to insert if SQLite is being used?
> 
> 
> I don't want to feed you incorrect information here so hopefully
> someone will confirm.
> create, insert and populate do not need to be supplied a id  (where id
> is a Primary Key, with or without auto-increment). That is taken care
> of by DBIx::Class::PK::Auto. You use id generally for search/find.
> Omit the id from your hashref.

Thanks Dermot,

I'm now going through all of my code and removing the id field from
everywhere.

(Un)fortunately, this was a case of reading from a stale replicated
MySQL server, which is why I could not see the updates. Having the id
field in tact, broke completely when running my tests.

All is well now, and I've learnt a great deal in the process.

Steve



More information about the DBIx-Class mailing list