Support custom ID fields #9
Reference in New Issue
Block a user
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:
PositionQuestionAnd, the created routes:
PositionQuestionThis is indeed weird, hmm...
One thing is, we use
{ id: request.query.id }for finding byid, and you are using custom fields,questionIdandpositionId.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/1and/question/1throws 500./positions/1and/questions/1throws 400, with message "child "scope" fails because ["scope" must be one of []]"./poisitionsand/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
ids.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
positionentity has 8 routes defined, and thequestionjust 4? Or, are these two questions/issues related?@casalot: Maybe you have relations/associations defined for your
Positionmodel?Nope. Neither
PositionnorQuestionhas 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: trueon both entities. Didn't make a difference.Changing the id from
positionIdtoidon 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! 👍