chicagoboss

boss_db:save_record not working with PostgreSQL adapter


I'm trying to save a BossRecord to the database using pgsql adapter, of this way:

boss_db:save_record(admins:new("admins-1", 1)). 

In ChicagoBoss's shell this returns:

{ok,{admins,"admins-1",1}}

But the record is not actually being saved in the database.

This is my table:

CREATE TABLE admins("
        "ID integer primary key,"
        "user_ID integer"
    ")

My model:

-module(admins, [Id, UserId]).
-compile(export_all).

Thanks.


Solution

  • Thanks to Evan Miller I've found the solution, like here he says evan miller ChicagoBoss blog "the Id field of each model is assumed to be an integer supplied by the database (e.g., a SERIAL type in Postgres)... specifying an Id value other than the atom 'id' for a new record will result in an error"

    So I changed my table to:

            "CREATE TABLE IF NOT EXISTS admins("
                "ID serial primary key,"
                "user_ID integer"
            ")"
    

    And also change the model (to specify the name of the table and the columns):

    -module(admin, [Id, UserId]).
    -columns([{id, "ID"}, {user_id, "user_ID"}]).
    -table("admins").
    

    And using 'id' atom to save the record:

    boss_db:save_record(admins:new(id, 1)).