Questions tagged [model]
Part of the MVC pattern, the Model manages the behaviour and data of the application.
21,475
questions
30
votes
3
answers
5k
views
problem with passing booleans to update_attributes
I've got the following Model:
class GuestCatering < ActiveRecord::Base
# Validation
validates :name, :presence => true
validates :order_number, :presence => true
validates :...
30
votes
5
answers
49k
views
MVC Validation Lower/Higher than other value
How is the best way to validate a model in MVC.Net where I want to accept a minimum/maximum.
Not individual min/max values for a field. But separate fields for a user to specify a minimum/maximum.
...
30
votes
6
answers
30k
views
Which 3D Model format should I be using? [closed]
Im writing a game engine and I'm wondering what 3D model format should I use/load/export? Obj seems universal and easy but it also appears to be unreliable in that most models out there contain errors ...
30
votes
3
answers
14k
views
Using javafx.beans properties in model classes
Is it a correct practice to use JavaFX beans properties in the model classes?
I wonder if it is a good practice to use properties in model classes to be able to bind them easier with the view ...
30
votes
1
answer
32k
views
ES6 Classes for Data Models
I'm trying to use ES6 Classes to construct data models (from a MySQL database) in an API that I'm building. I prefer not using an ORM/ODM library, as this will be a very basic, simple API. But, I'm ...
29
votes
5
answers
9k
views
Best way to make one model 'selected' in a Backbone.js collection?
I have a collection of models in my Backbone.js application.
It's a list of items that you can hover over with the mouse or navigate around with the keyboard.
If the mouse is hovering, or if the ...
29
votes
4
answers
89k
views
MVC 4 - Use a different model in partial view
Please bear with my noobness, I'm super new to the MVC pattern.
What I'm trying to do
I am building a profile information page for registered users on my site. This page would list data about the ...
29
votes
1
answer
64k
views
Model Containing List of Models (MVC-3, Razor)
This problem has been plaguing me for two days now. There are some similar posts, but none that address my problem completely.
Using MVC-3, Razor syntax:
-- EDIT.cshtml --
@using (Html.BeginForm(...
29
votes
6
answers
10k
views
How to organize Rails models that are too fat?
It is good practice to shift logic from the controller into the model. But in any complex system, this invariably leads to a very large file even if a majority of the methods are one liners as per the ...
29
votes
3
answers
24k
views
How to train the network only on one output when there are multiple outputs?
I am using a multiple output model in Keras
model1 = Model(input=x, output=[y2, y3])
model1.compile((optimizer='sgd', loss=cutom_loss_function)
my custom_loss function is
def custom_loss(y_true, ...
29
votes
1
answer
4k
views
Re-using Backbone.js models on the server side with Node.js and Websockets
I've been working my way through:
http://blog.andyet.com/2011/02/15/re-using-backbonejs-models-on-the-server-with-node
I have a few questions about sharing models server-side and a few questions ...
28
votes
3
answers
20k
views
Should I use an int or a long for the primary key in an entity framework model
I am writing an MVC5 Internet application and I have a question about the id field for a model.
Should I use an int or a long for the id in a model? I am talking about the field that is used for the ...
28
votes
3
answers
25k
views
django update_or_create gets "duplicate key value violates unique constraint "
Maybe I misunderstand the purpose of Django's update_or_create Model method.
Here is my Model:
from django.db import models
import datetime
from vc.models import Cluster
class Vmt(models.Model):
...
28
votes
5
answers
11k
views
getting the values from a nested complex object that is passed to a partial view
I have a ViewModel that has a complex object as one of its members. The complex object has 4 properties (all strings). I'm trying to create a re-usable partial view where I can pass in the complex ...
28
votes
3
answers
14k
views
Django model inheritance: Create a subclass using existing super class
I'm using multi-table-inheritance, and want to know how to create an inherited type from an instance of the superclass.
Using the example given in the documentation:
class Place(models.Model):
...
28
votes
5
answers
19k
views
Why Two Classes, View Model and Domain Model?
I know it could be bad to use domain models as view models. If my domain model has a property named IsAdmin and I have a Create controller action to create users, someone could alter my form and get ...
28
votes
3
answers
8k
views
Python/Django: synonym for field "type" in database model (reserved built-in symbol)
I created a django project. It contains a model class with a "type" attribute. I think that "type" is the most appropriate term to describe that field, because it defines the kind of the entry.
...
28
votes
4
answers
18k
views
Rails table_name_prefix missing
I have got the following dir structure
models/foo/setting.rb
models/foo.rb
foo.rb content
module Foo
def self.table_name_prefix
'foo_'
end
end
and setting.rb content
class Foo::Setting &...
27
votes
1
answer
7k
views
How to use different authentication_keys for two devise models?
Now I have one devise model, which uses email as authentication_key.
I want to add one new devise model, which uses student_id as authentication_key.
Some guide tells me to modify the configuration
...
27
votes
4
answers
25k
views
How to remove the prefix of a table for a Django model?
I create a new Django app (not project) called Bussinesses, then add following class to the models.py.
class Bussinesses(models.Model):
business_email = models.EmailField()
password = models....
27
votes
4
answers
24k
views
Best practices for grails index page
What is the right way to populate the model for the index page in a grails app? There is no IndexController by default, is there some other mechanism for getting lists of this and that into the model?
27
votes
5
answers
47k
views
attribute dependent on another field
In a model of my ASP.NET MVC application I would like validate a textbox as required only if a specific checkbox is checked.
Something like
public bool retired {get, set};
[RequiredIf("retired",...
27
votes
12
answers
89k
views
Cast string to float is not supported in Linear Model
I keep getting this error in my linear model:
Cast string to float is not supported
Specifically, the error is on this line:
results = m.evaluate(input_fn=lambda: input_fn(df_test), steps=1)
If ...
27
votes
4
answers
27k
views
Model Inheritance in Laravel
i'm currently working with Laravel and I'm struggling with the fact that every model needs to extend from Eloquent and I'm not sure how to implement a model Hierarchy (with different tables)
For ...
27
votes
4
answers
18k
views
Backbone change model of View
I am fairly new to Backbone and have the following question:
I have a collection of models.
I have a collection view displaying tabs (with a view for each model in the collection).
I have a view ...
27
votes
5
answers
1k
views
How to model interpretations of rap music
I just started working on a website that will help people understand what rappers are talking about. Users will see the lyrics to a rap song and they'll be able to click certain lyrics to see an ...
26
votes
2
answers
24k
views
Check if record exists in CakePHP3
In CakePHP 2 I always used empty to check if there any result.
<?php
$result = $this->Modelname->find('first', ['conditions' => ['field' => 'value'] ] );
if ( empty($result) ) {
// Bad ...
26
votes
4
answers
24k
views
How to validate only part of the model in ASP .NET MVC?
I have a large model (large I mean model class contains a lot of fields/properties and each has at least one validation attribute (such as Required, MaxLength, MinLength etc)). Instead of creating one ...
26
votes
1
answer
10k
views
Django MVC pattern for non database driven models?
I'm just working my way through Django, and really liking it so far, but I have an issue and I'm not sure what the typical way to solve it.
Suppose I have a View which is supposed to be updated when ...
26
votes
1
answer
9k
views
Django: Creating a Mixin for Reusable Model Fields
I've got a few fields that I want to add to most every model in my project. For example, these fields are "tracking fields" such as a created date, an update date, and an "active" flag. I'm ...
26
votes
4
answers
18k
views
What are the Laravel naming conventions for controllers/models/views?
I remember hearing you should name your controllers, models and views in a special way. Either singular or plural. I don't remember which ones to name what though, and i can't find anything about it ...
25
votes
2
answers
19k
views
How to move the laravel 5.1 User model to \App\Models\User?
Is it possible to tell Laravel that I have moved the User.php model?
Laravel 5.1
FatalErrorException in EloquentUserProvider.php line 126:
Class '\App\User' not found
I really wasn't keen on ...
25
votes
5
answers
12k
views
validate at least one in has_and_belongs_to_many
I have a model with:
has_and_belongs_to_many :users
How do I validate that the model has at least one user in the model? I tried:
validates_presence_of :users
But that doesn't seem to give me ...
25
votes
1
answer
89k
views
MVC Html.TextBoxFor MaxLength and Value
I am trying to setup a TextBox control in my project using Html.TextBoxFor.
However, it only seems to have method signatures for either:
Lambda Expression and Value:
<%= Html.TextBoxFor(t =&...
25
votes
3
answers
64k
views
Django models filter by foreignkey
I'm having some trouble in filtering objects from a set of models. Here is the problem:
I have 3 classes:
class Autor(models.Model):
nome = models.CharField(max_length=50)
slug = models....
25
votes
12
answers
29k
views
Spacy link error
When running:
import spacy
nlp = spacy.load('en')
the following is printed:
Warning: no model found for 'en'
Only loading the 'en' tokenizer.
/site-packages/spacy/data is empty with the ...
25
votes
2
answers
24k
views
Is there a way to get attributes // associations by previously defined Sequelize Model?
I need to get some data by previously defined Sequelize Model.
What I need:
* attributes list
* attribute name
* attribute type (INTEGER, STRING,...)
* was it generated by association method?
*...
25
votes
9
answers
50k
views
How to store a dictionary in a Django database model's field
I need to save a dictionary in a model's field. How do I do that?
For example I have this code:
def create_random_bill(self):
name_chars = re.compile("[a-zA-Z0-9 -_]")
bill_name = "".join(...
25
votes
13
answers
60k
views
Incompatible Data Reader Exception From EF Mapped Objects
I am using Entity Framework and have updated a table and its stored procedure but I'm getting the following error when the stored procedure is called.
The data reader is incompatible with the ...
25
votes
3
answers
25k
views
Sequelize: seed with associations
I have 2 models, Courses and Videos, for example. And Courses has many Videos.
// course.js
'use strict';
module.exports = (sequelize, DataTypes) => {
const Course = sequelize.define('Course', {...
25
votes
5
answers
18k
views
How to set view model on ViewResult in request filter?
I make a MVC project and I want set Model into View from filter.
But I do not kown ,How can I do this.
the Model:
public class TestModel
{
public int ID { get; set; }
public string Name { ...
25
votes
2
answers
22k
views
Entity Framework Code First List<string> Property Mapping
I am working with Entity Framework Code first. I have a simple model:
public class Variable
{
public string Name { get; set; }
public int Id { get; set; }
public IList<string> ...
25
votes
2
answers
9k
views
Creating a gem that contains rails models
I've been reading a lot on the topic and nothing seems to quite cover my needs. I'm sorry if I'm repeating or unclear about something I'm both new to ruby and rails and new to Stack Overflow.
I have ...
25
votes
1
answer
3k
views
Trigger Odoo fields_view_get dynamically after all records being loaded and fields_view_get function called
I’d like to trigger the fields_view_get function dynamically after doing some functions. I override the function fields_view_get and return my results. This gets affected on XML view only at first ...
24
votes
2
answers
11k
views
Is it possible to use rails image_tag from inside a model?
I have a rails 3.x application that has model classes which return content to a view partial to be rendered on a page. The model takes care of what the content is and just returns it to the view which ...
24
votes
4
answers
20k
views
Rails - How to validate a field only if a another field has a certain value?
In my form I have a Select with three values: Apple, Banana and Cherry. If I choose Apple from the select I hide another Select- and a Text-field with some Javascript, because when Apple is chosen, ...
24
votes
3
answers
20k
views
Rails: Modifying a Model Generated by Scaffolding
How do you modify a model you've generated using modeling? For example, the model myModel originally had columns a, b and c, but I now want to add column d.
24
votes
2
answers
11k
views
Turn off "updated_at" column in Rails
I have a simple "Log" model, that records the fact of calling controller's action.
Entries of this "log" record are supposed to be created once and never altered. Also, I will have many of these ...
24
votes
1
answer
27k
views
Django CharField with no max length
I have a frontend that will be sending bas64 images, I will put those very large strings on a variable and send it to a form. What kind of FormField can I use?
The regular CharFields need a ...
24
votes
6
answers
48k
views
Pass an entire model on form submission
I understand that I can use @Html.HiddenFor(m => m.parameter) and when the form is submitted, that parameter will be passed to the controller. My model has many properties.
Is there a shorter way ...