Skip to content

id field always named id in generated resources, event for non-standard id names #89

Closed

Description

@pandaiolo

When configuring model with specific id field (not id), angular resources still expect id property to contain id :

    "findById": {
      url: urlBase + "/Member/:id",
      method: "GET",
    },

My Member model id field is actually named username, which makes this confusing because sometimes id must be used and some other time username (when it's not an angular resource expected id field)

Note : additionally, the above resources is used by calling Member.findById({id: xxx}), what about wrapping that in a more isomorphic findById that would only take the id as argument like on the server : Member.findById(xxx) ?

Activity

  1. bajtos commented on Oct 23, 2014

    @bajtos
    Member

    My Member model id field is actually named username, which makes this confusing because sometimes id must be used and some other time username (when it's not an angular resource expected id field)

    Does the REST API work for you when the id property is not named :id? AFAIK, constructor's REST route is always /:id. I am not sure if this :id parameter is internally converted to :username, I would expect it is not.

    Related discussion: strongloop/loopback#126

    What I find interesting: my assumption was that front-end devs would prefer the consistency of using id everywhere, as opposed to consistent id property name between the client and the server.

    Note : additionally, the above resources is used by calling Member.findById({id: xxx}), what about wrapping that in a more isomorphic findById that would only take the id as argument like on the server : Member.findById(xxx) ?

    So far the generated Model resources were conforming to ngResource API. While the ngResource module has many problems, it is at least a part of Angular, thus Angular devs should be familiar with it. There are also things like request/response interceptors that we have for free now.

    Your proposal would move the SDK away from ngResource API towards an isomorphic API. It's an interesting idea. It makes me wonder if we can come up with an API that would be close to what is proposed in #83, thus splitting the whole transition into multiple smaller steps.

    Unfortunately the Angular SDK is not a high priority for us now, I won't have time to implement these changes myself. And as you can see, I don't have enough time to guide you through big pull requests like #84 either :(

    To keep this actionable: if you don't mind slow pace of progress, we can discuss incremental steps how to change the codegen to produce the new API. Alternatively, you can create an alternate/unofficial SDK code generator in your own repo and do all the work there, without waiting for my review/approval.

  2. pandaiolo commented on Oct 23, 2014

    @pandaiolo
    ContributorAuthor

    What I find interesting: my assumption was that front-end devs would prefer the consistency of using id everywhere, as opposed to consistent id property name between the client and the server.

    Actually, only the REST route variable is named 'id', the object themselves use the configured id property name, hence username : the data is returned to the client with username, and the same is used in angular to access the value, etc.

    So even for a pure angular developper dealing with client-side-only code, he will have to call p = Profile.findById({id: xx}) but then use p.username to access the value on the resulting object.

    For the integration of my contributed code, nevermind if you don't have time, I try to keep in sync with the main repo by rebasing my branch every now and then.

    I also agree with your point on sticking to ngResource/angular way of things

  3. bajtos commented on Apr 19, 2018

    @bajtos
    Member

    Looks like the discussion ended more than three years ago, I am closing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions