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.

(feature request) Guarded and fillable properties for mass assignment.

See original GitHub issue

I really like being able to use mass assignment but also be able to protect certain columns from being updated.

In the style of: http://laravel.com/docs/eloquent#mass-assignment

Guarded properties that can be updated via mass assignment:

module.exports = function(bookshelf) {
  return bookshelf.Model.extend({
    tableName: 'account_benefits',
    fillable: ['name', 'description']
  });
};

OR

Guarded properties that can be updated via mass assignment:

module.exports = function(bookshelf) {
  return bookshelf.Model.extend({
    tableName: 'account_benefits',
    guarded: ['id', 'created_at', 'updated_at', 'deleted_at']
  });
};
var input = res.body;

new db.accountBenefit({ id: accountBenefitId })
  // In this case input contains id, name, description, and created_at.
  // Only name and description get new values.
  .save(input)
  .then(function(accountBenefit) {
    res.json({ accountBenefit: accountBenefit });
  });
});

Maybe a new method for it (fill?):

new db.userGoal({
  id: userGoalId,
  account_id: request.auth.credentials.account.id
})
.fill(request.payload)
.then(function(userGoal) {
  reply({ userGoal: userGoal });
});

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rhys-vdwcommented, Apr 7, 2016

@marco-fiset Nobody is working on this feature presently. I’d suggest building out a plugin if you need it.

0reactions
crunchtime-alicommented, Jul 19, 2017

The project leadership of Bookshelf recently changed. In an effort to advance the project we close all issues older than one year.

If you think this issue needs to be re-evaluated please post a comment on why this is still important and we will re-open it.

We also started an open discussion about the future of Bookshelf.js here https://github.com/bookshelf/bookshelf/issues/1600. Feel free to drop by and give us your opinion. Let’s make Bookshelf great again

Read more comments on GitHub >

github_iconTop Results From Across the Web

Laravel Mass Assignment, Guarded or Fillable?
Guarded is the reverse of fillable. If fillable specifies which fields to be mass assigned, guarded specifies which fields are not mass assignable....
Read more >
What does "Mass Assignment" mean in Laravel?
Guarded is the reverse of fillable. If fillable specifies which fields to be mass assigned, guarded specifies which fields are not mass ...
Read more >
Laravel mass assignment and fillable vs guarded - Tallpad
In this video we'll take a look over mass assignment in Laravel and whether to go with $fillable or $guarded when protecting against...
Read more >
$fillable and $guarded don't work when use update()? #39305
Hi, I use Laravel 8.41.0 and I have a question: Why $fillable and $guarded don't work when I use update() to update data?...
Read more >
When mass assignment is happening? - Laracasts
Hi, i got a question. I got confused by mass assignment and fillable attribute. In my controller, in store method i have something...
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