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.

userModel is not extended correctly

See original GitHub issue

When extending the user model, nested arrays are not concatenated their positions are overwritten.

ie:

var userModelConfig = {whitelist: ['1','2','3','4','5','6']}
var userModel = {whitelist: ['a','b','c']}

$.extend(true, {}, userModel, userModelConfig)
//returns
{"whitelist":["1","2","3","4","5","6"]}

and
$.extend(true, {}, userModelConfig, userModel)
"{"whitelist":["a","b","c","4","5","6"]}"

As you can see the index position of the array is overwritten rather then extend or merged.

A potential solution would be to transform the arrays into objects, extend them and transform them back.

I was going to try to fix it and submit a pull request, but i dont have the time tonight so i wanted to get this to you, maybe you have a quicker solution.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
colinskowcommented, Dec 29, 2015

OK, now I understand exactly what you are saying. Currently if you want to change the whitelist, you have to repeat it:

whitelist: [
      'name',
      'username',
      'email',
      'password',
      'confirmPassword',
      ...
    ],

I’ll work on this for the next version of SuperLogin, but don’t know when I’ll get to it. If you can do I pull request with a passing test in user.spec.js then I would be happy to merge it.

0reactions
raymatoscommented, Dec 29, 2015

So what im trying to say is the node extend is basically a clone to jquery extend. And extend will not merge 2 arrays.

So for example, if you were to add this to the config file

userModel: {
    whitelist: [
      'interests',
      'unit',
      'age',
      'subscribe',
      'zipcode'
    ]
  }

You would get an error saying the username, password, and confirmPassword is required. This is because userModel = extend(true, userModel, config.getItem('userModel')); would return the whitelist array like this

whitelist: [
      'interests',
      'unit',
      'age',
      'subscribe',
      'zipcode'
    ]

This is because extend will overwrite the array rather then merge them. But what you really want is a unique merge.

Hope that makes more sense.

Read more comments on GitHub >

github_iconTop Results From Across the Web

django - Extended user model not save password correctly
im trying to create a child and parent objects at the same time with same form. After migrations, i have two tables, user...
Read more >
Data not saving correctly · Issue #76 · szokodiakos/typegoose
I want to save a mongoose document with a typegoose sub-document but data isn't saving correctly. Car Model does not extend Typegoose
Read more >
How to Extend Django User Model
Ways to Extend the Existing User Model · Option 1: Using a Proxy Model · Option 2: Using One-To-One Link With a User...
Read more >
Extending the existing User model - Using Django
Hi, now I try to extend the user model of my django app to store a pin and a balance with the useraccount...
Read more >
is this a correct way to extend the user model , how to create a view ...
Here's an example: class MyUser(AbstractUser): bio = models.CharField(...) Note that date_joined is already a field on AbstractUser , you don't need to ...
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