Support custom ID fields #9
Labels
No Label
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: thereadme/hapi-sequelize-crud#9
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@mdibaiee, I'm seeing some strange behaviour with the auto route creation.
Here's an example of 2 of my entity models:
Position
Question
And, the created routes:
Position
Question
This is indeed weird, hmm...
One thing is, we use
{ id: request.query.id }
for finding byid
, and you are using custom fields,questionId
andpositionId
.But you say the Position model's id route works! Now that's inconsistency. Do you get any errors/warnings?
Let me see if I can reproduce your problem.
/position/1
and/question/1
throws 500./positions/1
and/questions/1
throws 400, with message "child "scope" fails because ["scope" must be one of []]"./poisitions
and/questions
(without id's) works 100%.Okay, so it's not inconsistency, is it? You get the same routes for both models, if that's the case, your problem is with
id
s.You have
positions/{scope}
, notpositions/{id}
, instead there isposition/{id}
(which doesn't work in your case.If I'm correct, the problem is with custom id fields.
I think the custom id is one of the issues. I don't understand why the
position
entity has 8 routes defined, and thequestion
just 4? Or, are these two questions/issues related?@casalot: Maybe you have relations/associations defined for your
Position
model?Nope. Neither
Position
norQuestion
has any relations defined.Umm, I'm not sure about that. But I think we can address the id issue here, and if you encounter any problem with the routes, we'll get to that later. What do you say?
Cool. Should I rename the custom id's to
id
? Or, is there a why to alias it?I think we should allow custom id fields, I'm seeing if there is a way to automatically detect ID fields (using PRIMARY KEYs, INDEXes, etc.), or we should ask the programmer to explicitly set the custom field's name.
I have set
primaryKey: true
on both entities. Didn't make a difference.Changing the id from
positionId
toid
on the database table, now gets results back for/position/1
.Okay it seems there is a way to automatically use the primary key set by programmer, I'm going to patch it right now. 👍
Published to npm
hapi-sequelize-crud@2.4.0
, see if it works for you.Working perfect now!
Great! 👍