On Sunday, September 14, 2014 1:01:41 PM UTC-7, Marcio Andrey Oliveira 
wrote:
>
> Hi, all.
>
> I'm making an app using Padrino with Sequel.
>
> In order to easy my work I made an utility function that creates a basic 
> user where I can provide just a basic info (username and password) and all 
> remaining fields are filled with predefined values.
>
> Then I made a test application. My problem is that even having all fields 
> being filled (and tests assure this), when I call save method in model I 
> get a NotNullConstraintViolation exception.
>
> Looking at the error message we can see that in fact almost no fields are 
> filled in SQL .
>
> ←[0m←[1000D←[KERROR["test_0041_creates a client account using 
> get_new_client. All data filled.", #<Class:0x404ccb8>, 0.006001]
>  test_0041_creates a client account using get_new_client. All data 
> filled.#User 
> Model (0.01s)
> Sequel::NotNullConstraintViolation:         Sequel::
> NotNullConstraintViolation: PG::NotNullViolation: ERROR:  null value in 
> column "username" violates not-null
> constraint
>         DETAIL:  Failing row contains (7, null, null, null, null, null, 
> null, t, t, null, 0, 0, C, T, 2014-09-14 16:35:48.155, null).
>
>
> But why ? The model has it's fields filled. Can you please take a look at 
> both the model snippet and unit test snippet and tell me what am I doing 
> wrong?
>
> I'm using Sequel 4.14.0. The problem happens on both Postgres and SQLite 
> databases.
>
> Ay help is very appreciated.
>
> Thanks in advance.
>
>
> Snippet of my My user model:
>
> class User < Sequel::Model
>
>   set_allowed_columns :username, :password, :points
>   attr_accessor :username, :password, :points, :trial_expires_at, :role, :
> fullname, :about, :status, :uuid
>   attr_reader :created_at, :updated_at, :trial_expires_at
>

Here's your bug.  You are overridding the column getters and setters that 
Sequel::Model automatically creates (which store values in the @values 
hash), and replacing them with simple attribute getters/setters that store 
values in instance variables.  Just remove these attr_accessor and 
attr_reader calls.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to