creates and saves model instance with collection of UserSocialAuth

        Raise:
            NotImplemetedError
167712
def get_or_create_with_social_auth(self, social_auth):
        
        # Type check
        self.assert_user_is_social_auth_user(social_auth)

        # Fetch the record
        try:
            social_friend_list = self.filter(user_social_auth=social_auth).get()
        except:
            # if no record found, create a new one
            friend_ids = self.fetch_social_friend_ids(social_auth)

            social_friend_list = SocialFriendList()
            social_friend_list.friend_ids = friend_ids
            social_friend_list.user_social_auth = social_auth
            social_friend_list.save()

        return social_friend_list
43587
function userStored(model, error) {
          if (typeof error != 'undefined') {
            callback(error);
            return;
          }
          if (user1.get('id') && user2.get('id')) {
            // users added to store now log them both in and also generate 2 errors
            self.goodCount = 0;
            self.badCount = 0;
            session1.startSession(store, name1, 'badpassword', ip1, usersStarted);
            session1.startSession(store, name1, pass1, ip1, usersStarted);
            session2.startSession(store, 'john', pass2, ip2, usersStarted);
            session2.startSession(store, name2, pass2, ip2, usersStarted);
          }
        }
63604
function initModelUpdate (args) {
    var controller = this
    var model = this.model
    // if model does not have id column then cannot use default controller
    if (!model.columnName('id') || !model.columnName('parentId')) {
        return
    }
    // get accountId column
    var accountIdColumn = model.columnName('accountId') 
    // set role to authenticated if model requires account id
    var role = args.defaultRole || (accountIdColumn && model.columns[accountIdColumn].null === false ? 'authenticated' : 'all')
    // index inputs
    var input = {
        // get current revision of instance
        current: 'query.current',
        // get record even if deleted
        deleted: 'query.deleted',
        // ignore conflicts
        force: 'query.force',
        // instance id
        id: 'params.id',
        // merge update data into existing data
        merge: 'query.merge',
        // input data includes meta columns
        meta: 'query.meta',
    }
    // instance data is in body under model name
    input[model.name] = 'body.'+model.name
    // create path for PUT for API requests
    if (!this.paths['/:id']) {
        this.paths['/:id'] = {}
    }
    // create path for POST for form requests
    if (!this.paths['/:id/update']) {
        this.paths['/:id/update'] = {}
    }
    // add handler for PUT /:id and POST /:id/update
    // to update instance
    this.paths['/:id'].put = this.paths['/:id/update'].post = [
        {
            before: function (args) {
                // load model
                return loadRecordForUpdate(controller, args)
            },

            input: input,
            method: function (args) {
                // perform update
                return update(controller, args)
            },
            methodName: 'update',
            role: role,
            template: 'instance',
        },
    ]
}
264429
function getUser(username, done) {
  return getModels(function(m) {
    return m.collections.user.findOne({ username })
      .populate("tokens")
      .populate("groups")
      .populate("leading")
      .exec(done);
  });
}
1259736
function _createUser(){
    var excludedFields = ['name', 'screen_name', 'profile_image'],
        nameparts = this.options.user.full_name.split(' '),
        newUser = {
        role: 'external',
        identities: {
            instagram: {
                id: this.options.user.id,
                accessToken: this.options.access_token,
                screen_name: this.options.user.username
            }
        },
        linkedidentities: ['instagram'],
        profile: {
            picture: this.options.user.profile_picture
        },
        enabled: true,
        email: '',
        firstname: nameparts[0],
        displayname: this.options.user.username,
        lastname: (nameparts.length > 1) ? nameparts[1] : ' '
    };

    _.each(profileFieldsArr, function(field){
        if(excludedFields.indexOf(field) === -1){
            newUser.profile[field] = this.socialUserInfo[field];
        }
    }.bind(this));

    return db.users.insert(newUser);
}
1100439
def association_with_root_model(method_name)
      persistor = self.persistor || (respond_to?(:save_to) && save_to && save_to.persistor)

      # Check if we are on the store collection
      if persistor.is_a?(Volt::Persistors::ModelStore) ||
         persistor.is_a?(Volt::Persistors::Page)
        # Get the root node
        root = persistor.try(:root_model)

        # Yield to the block passing in the root node
        yield(root)
      else
        # raise an error about the method not being supported on this collection
        fail "#{method_name} currently only works on the store and page collection (support for other collections coming soon)"
      end
    end
875593
def _register_user_models(user_models, admin=None, schema=None):
    
    if any([issubclass(cls, AutomapModel) for cls in user_models]):
        AutomapModel.prepare(  # pylint:disable=maybe-no-member
                               db.engine, reflect=True, schema=schema)

    for user_model in user_models:
        register_model(user_model, admin)
675950
def save
      raise EntityModelIsNotPersistedError unless entity.persisted?

      if persisted?
        return false unless changed?
        update
      else
        create
      end

      @previously_changed = changes
      @changed_attributes.clear

      true
    end
331789
def add_instance(model, _commit=True, **kwargs):
    
    try:
        model = get_model(model)
    except ImportError:
        return None

    instance = model(**kwargs)
    db.session.add(instance)

    try:
        if _commit:
            db.session.commit()
        else:
            db.session.flush()
        return instance.id
    except IntegrityError:
        db.session.rollback()
        return
568086
def association(name)
      if reflection = _scope.reflect_on_association(name)
        Association.new(self, reflection)
      else
        raise AssociationNotFoundError.new(_scope.model_name, name)
      end
    end
420079
function OauthAuthMethods(models) {
      this.models = models;
      this.exchangeRefreshTokenForAccessToken = bind(this.exchangeRefreshTokenForAccessToken, this);
      this.exchangeAuthorizationCodeForAccessToken = bind(this.exchangeAuthorizationCodeForAccessToken, this);
      this.createTokenForUserId = bind(this.createTokenForUserId, this);
      this.createOrReuseTokenForUserId = bind(this.createOrReuseTokenForUserId, this);
      this.createAccessGrant = bind(this.createAccessGrant, this);
      this.validate = bind(this.validate, this);
      this.appForClientId = bind(this.appForClientId, this);
      this.currentDateAndSeconds = bind(this.currentDateAndSeconds, this);
      Hoek.assert(this.models, i18n.assertModelsRequired);
      Hoek.assert(this.models.OauthApp, i18n.assertOauthAppInModels);
      Hoek.assert(this.models.OauthAccessToken, i18n.assertOauthAccessTokenInModels);
      Hoek.assert(this.models.OauthAccessGrant, i18n.assertOauthAccessGrantInModels);
    }
450355
def create
      authorize model

      @resource = model.new(creation_params)
      @resource.assign_attributes(**reflections_hash) unless reflections_hash.nil?

      # Customize the create behaviour
      before_create_hook(@resource)

      # TODO: Handle M2M relations in here
      if @resource.save
        after_create_hook(@resource)
        successful_response(:create)
      else
        errorful_resopnse(:create, @resource.errors) do
          redirect_to Rails.application.routes.url_helpers.send(@new_route)
        end
      end
    end
247785
def create_user(self, **kwargs):
        """"""
        kwargs = self._prepare_create_user_args(**kwargs)
        user = self.user_model(**kwargs)
        return self.put(user)
722901
def create_user_model
      fname = "app/models/#{user_class.underscore}.rb"
      unless File.exist?(File.join(destination_root, fname))
        template("user_model.rb", fname)
      else
        say_status('skipped', "Model #{user_class.underscore} already exists")
      end
    end
453110
def create(self, request, *args, **kwargs):
        """"""
        collections = request.data.get('collections', [])

        # check that user has permissions on all collections that Data
        # object will be added to
        for collection_id in collections:
            try:
                collection = Collection.objects.get(pk=collection_id)
            except Collection.DoesNotExist:
                return Response({'collections': ['Invalid pk "{}" - object does not exist.'.format(collection_id)]},
                                status=status.HTTP_400_BAD_REQUEST)

            if not request.user.has_perm('add_collection', obj=collection):
                if request.user.has_perm('view_collection', obj=collection):
                    raise exceptions.PermissionDenied(
                        "You don't have `ADD` permission on collection (id: {}).".format(collection_id)
                    )
                else:
                    raise exceptions.NotFound(
                        "Collection not found (id: {}).".format(collection_id)
                    )

        self.define_contributor(request)

        if kwargs.pop('get_or_create', False):
            response = self.perform_get_or_create(request, *args, **kwargs)
            if response:
                return response

        return super().create(request, *args, **kwargs)
118410
def save
            unless [ :handle, :new, :modify, :save ].all?{|method| api_methods[method] }
                raise "Not all necessary api methods are defined to process this action!"            
            end
            entry = self.class.find_one(name)
            self.class.in_transaction(true) do |token|
                if entry
                    entryid = self.class.make_call(api_methods[:handle],name,token) 
                else
                    entryid = self.class.make_call(api_methods[:new],token)
                    self.class.make_call(api_methods[:modify],entryid,'name', name, token)
                end
                
                cobbler_record_fields.each do |field|
                    field_s = field.to_s
                    if !locked_fields.include?(field) && user_definitions.has_key?(field_s)
                        self.class.make_call(api_methods[:modify],entryid,field_s, user_definitions[field_s], token)
                    end
                end
                
                cobbler_collections_store_callbacks.each do |callback|
                    send(callback,entryid,token)
                end
                
                self.class.make_call(api_methods[:save],entryid,token)
            end
        end
659282
function (next, model) {
            var loaded = this.associationLoaded(model), val;
            if (loaded && (val = this.getAssociation(model))) {
                this._setAssociationKeys(model, val);
                val.save().classic(next);
            } else {
                next();
            }
        }