Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$resource->pivot->save() not working #11

Open
DavidPhilip opened this issue Nov 16, 2014 · 2 comments
Open

$resource->pivot->save() not working #11

DavidPhilip opened this issue Nov 16, 2014 · 2 comments

Comments

@DavidPhilip
Copy link

In my case I'm calling this:

$club->members->each(function($member) {
  $member->pivot->confirmed = true;
  $member->pivot->admin = true;
  $member->pivot->save();
});

resulting in this error:

file: "/Applications/XAMPP/xamppfiles/htdocs/agilitybase/vendor/j42/laravel-firebase/src/j42/LaravelFirebase/Client.php"
line: 253
message: "Invalid model object received: no primary ID (id, _id, $id)"
type: "UnexpectedValueException"

I'm not sure how to handle this error.

Also there seems to be another issue:$member is of model-type Userwhere $firebase = false; and also sync => false in the settings. Nevertheless there is the attempt to sync the model...

Please tell if you need more info. Regards,
David

@j42
Copy link
Owner

j42 commented Nov 16, 2014

David,

Apologies for the confusion--the sync will actually not be processed in this case (if you see an HTTP request please advise otherwise), however the model checks are run regardless in the __call overloaded method...

As for the error, it is expected that your model will inherit from Eloquent or otherwise include a getPrimaryKey() method that returns a Firebase-compatible key. Alternatively (if not present) it will fall back to check for common variants (id, _id, $id).

If none of these defaults meet your use case (perhaps since you seem to be using pivot tables), could you provide more context for what you're trying to achieve?

@DavidPhilip
Copy link
Author

I think the issue is the call of ->save() as that seems to be the hook where the checks are fired for this plugin regardless of what I've declared in my settings as you already mentioned.

I used ->pivot to change the values of the model in the pivot table and saved those changes by calling ->save(). I ended up setting the values while attaching the relationship like so:

$club->attach([$member_ids], ['confirmed' => true, 'admin' => true])

In that case I don't call ->save() and it works. So laravel-firebase kinda forces me to use that syntax or else it throws the aforementioned error. I will debug this at home and have a look at what kind of object the checks are run on. Maybe we can fix this by making an exception for some sort of type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants