I have a column that peeks its value from a sequence (postgres) some
times. Other times, I set it to a certain value.
This column has a default value of “nextval(‘the_sequence’)”… When I
want that this column peeks the value from the sequence, I do this:
obj = Mymodel.new
obj.some_column1 = blah
obj.some_column2 = blah
obj.some_column3 = blah
but when looking at the logs, this creates a sql statement like this:
INSERT INTO Mymodels (some_column1, some_column2, some_column3,
problem_column) VALUES (blah, blah, blah, NULL);
this is a problem, because it’s passing NULL and it’s not calling the
default value… the only solution I see here is to create a trigger for
insertion, that when the value is NULL set it to the next value from the
what’s the rails-way to do this?