statamic / eloquent-driver

Provides support for storing your Statamic data in a database, rather than flat files.
https://statamic.dev/tips/storing-content-in-a-database
MIT License
104 stars 71 forks source link

Unable to store form submission #286

Closed andreas-eisenmann closed 1 month ago

andreas-eisenmann commented 1 month ago

Scenario: create a form and set store submissions to true.

Now we have this call stack:

\Statamic\Http\Controllers\FormController::submit
|_ \Statamic\Eloquent\Forms\Submission::save
    |_ \Statamic\Eloquent\Forms\Submission::toModel

In toModel() we have:

$model = $class::findOrNew($this->id());

The result of $this->id() is a timestamp - no wonder, just look at the code:

https://github.com/statamic/cms/blob/7cbc505da6c7f2f9568599631b607aa427d5cc62/src/Forms/Submission.php#L52

return $this->id = $id ?: str_replace(',', '.', microtime(true));

Surprise, now we have a database exception:

SQLSTATE[22P02]: Invalid text representation: 7 ERROR:  invalid input syntax for type bigint: "1715767251.4272"
CONTEXT:  unnamed portal parameter $1 = '...' (Connection: pgsql, SQL: select * from "form_submissions" where "form_submissions"."id" = 1715767251.4272 limit 1)

How is this supposed to work?

ryanmitchell commented 1 month ago

It seems to be due to Postgres being less forgiving than other engines - see the comments here: https://github.com/statamic/eloquent-driver/pull/122#issuecomment-2111965758