spiral-project / daybed

Form validation and data storage API
http://daybed.rtfd.org/
BSD 3-Clause "New" or "Revised" License
53 stars 8 forks source link

Let's define a model field as primaryKey that will be used on the POST /records and validated with the recordId on PUT #274

Open Natim opened 9 years ago

leplatrem commented 9 years ago

Do you mean oneof ?

almet commented 9 years ago

Yeah, the title is not really self-explanatory.

What (I understood) we want here is a way to actually have a field of the data filled from data that's externally provided. For instance, we could have a field which matches the hawk id we're using, or have a field which is filled using the name of the model.

leplatrem commented 9 years ago

Okay, I believe I understood... Something like that :

{  name: "creator",
   type: "autofill",
   value: "CREDENTIALS_ID" }

With some constants like MODELNAME etc.

Well... I would have relied on the client to do that, but since I guess it should not be forged we have to do something server-side.

I still would like to see an explicit use-case to judge if the solution is relevant. For example, it can slightly be related to #222

almet commented 9 years ago

Actually we have two different things: the first one, the "autofill" type, which is useful when we want to associate a creator to a record, as you shown (for instance), and we also need a way to have the server check for us that the id of a record matches a specific notion (for instance the hawkid, or the firefox accounts email).

So that we are sure that /v1/models/keys/records/alexis@notmyidea.org was actually submitted by a verified account.

leplatrem commented 9 years ago

Ideally, it should have several obvious use-cases (the creator isn't one, since we can have #222). And from what you describe, I don't see it very generic and reusable :( Maybe should it be thought as a plugin ?

Natim commented 9 years ago

No that's not what I was talking about.

The idea is more having a field that IS the record primary key.

{  name: "slug",
   type: "string",
   primary: true
}

Then if I do a POST with:

{slug: "toto"}

It will answer:

{id: "toto"}

Also it will fail to validate if I do a PUT on /records/something if this something isn't toto.