question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Saving model with relations

See original GitHub issue

Hi, is there a way to save a models data with related models? I have a model User and it has a Profile and a Role.

I’m using backbone on the client side and i’m making a put to edit user info:

var userData = {
    "email": "info@luisbravoa.com",
    "Profile": {
        "firstname": "luis",
        "lastname": "bravo"
    },
    "Role": {
          "user_id": "1",
          "role_id": "3"
      }
} ;

How can i specified in the save method to save also related models, something like this:

User.forge({id: id})
   .save(userData, { withRealated: true})
   .then(function(model){
       // weeee
   })
   .otherwise(function(error){
     // :(
});

thanks very much!

Issue Analytics

  • State:open
  • Created 10 years ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
shinzuicommented, May 18, 2016

Is this feature in development? It’s hard to tell by looking at #552

1reaction
ricardogracacommented, Nov 26, 2019

I agree. I would also like to have this functionality.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to save Eloquent Model with relations in one go?
When saving a model with relations we do something like this; $ship = new Ship; $ship->name = 'Enterprise'; $ship->registry = 'ncc-1701D'; $ship->save(); ...
Read more >
Laravel Saving A Model And Relationships - Stack Overflow
I'm trying to update the Model Years with new Data, but can't seem the get it done. I tried the following: $movies =...
Read more >
Laravel saving model with relationship - Laracasts
Laravel saving model with relationship. Hi guys, I'm kinda new to laravel and I have a question. I have an Order model and...
Read more >
Saving Models and Their Relationships with JSON API
So the real question becomes: is there a correct way to save a model and all its relationships included in a single post...
Read more >
Eloquent: Relationships - The PHP Framework For Web Artisans
Inserting & Updating Related Models. The save Method; The create Method; Belongs To Relationships; Many To Many Relationships. Touching Parent Timestamps ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found