Skip to content

Client-generated id? #368

@llhilton

Description

@llhilton

I've looked through the old issues on this topic and haven't found help, so hoping I can get some clarity.

I am trying to create a resource called MoodleUser. This has an id that needs to match the ID from another system. I was under the impression from the docs that I could set the ID for a new MoodleUser in the Adapter using the creating hook, like so:

protected function creating(MoodleUser $moodleUser, $resource): void
    {
        $moodleUser->{$moodleUser->getRouteKeyName()} = $resource['lmsUserId'];
    }

Using Ember.js, I send the call like so:

newMoodleUser = this.store.createRecord('moodle-user', {
        lmsUserId: lmsUser.id,
        institutionId: institution.id,
      });
yield newMoodleUser.save();

That gives me a $resource in the creating hook that looks like this:

 array (
  'type' => 'moodle-users',
  'attributes' =>
  array (
    'lmsUserId' => '199',
    'institutionId' => '3',
  ),
)

Instead of making a new MoodleUser with the id of, say, 199, I get an error that "Id member is an empty string."

I tried some other things, like passing in an id attribute in the createRecord method, but that gave me a 403 error that client-generated ids weren't supported for the moodle-user resource.

I'm not sure what else to try or where else to look for assistance. Any help would be most appreciated!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions