Questions tagged [model]
Part of the MVC pattern, the Model manages the behaviour and data of the application.
21,474
questions
24
votes
4
answers
20k
views
Training own model in opennlp
I am finding it difficult to create my own model openNLP.
Can any one tell me, how to own model.
How the training shouls be done.
What should be the input and where the output model file will get ...
24
votes
7
answers
9k
views
Where does input validation belong in an MVC application?
I have a MVC application that receives an input from a form.
This is a login form so the only validation that is necessary is to check whether the input is non-empty.
Right now before I pass it to the ...
24
votes
2
answers
4k
views
Magento Proper Way To Reindex Single Item and associated Group product
What is the proper way to reindex a single item after modifications have been made to it.
Example context:
Our company relies on a third party inventory management platform called Stone Edge. We ...
23
votes
12
answers
40k
views
Error in admin: __str__ returned non-string (type NoneType)
The admin returns this error when trying to add an instance to one of my models. The model itself has a correct str() method and contains no instances yet. Also tried replacing the str() method with a ...
23
votes
5
answers
23k
views
Django ORM how to Round an Avg result
I have a model in which I use Django ORM to extract Avg of values from the table. I want to Round that Avg value, how do I do this?
See below I am extracting Avg price from Prices model grouped by ...
23
votes
8
answers
45k
views
How would I use ON DUPLICATE KEY UPDATE in my CodeIgniter model?
I have a CodeIgniter/PHP Model and I want to insert some data into the database.
However, I have this set in my 'raw' SQL query:
ON DUPLICATE KEY UPDATE duplicate=duplicate+1
I am using CodeIgniter ...
23
votes
15
answers
6k
views
Programming against interfaces: Do you write interfaces for all your domain classes?
I agree, that programming against interfaces is a good practice. In most cases in Java "interface" in this sense means the language construct interface, so that you write an interface and an ...
23
votes
3
answers
54k
views
ER-Diagram: Ternary Relationship - How to read properly?
Im not quite sure how to read ternary relationships within a ER-Diagram.
Lets say this is the ternary relationship that is given.
What can I interpret out of that?
It says that you have to put your ...
23
votes
2
answers
8k
views
Django: Using F arguments in datetime.timedelta inside a query
Using Django model syntax, if I do this:
ThatModel.objects.filter(
last_datetime__lte=now + datetime.timedelta(seconds=F("interval")))
I get:
TypeError: unsupported type for timedelta days ...
23
votes
1
answer
11k
views
JavaBean wrapping with JavaFX Properties
I want to use JavaFX properties for UI binding, but I don't want them in my model classes (see Using javafx.beans properties in model classes). My model classes have getters and setters, and I want to ...
23
votes
2
answers
11k
views
How to use routing helpers in a model with Rails 3?
In a model callback I make an API call and need to give the API some URLs. Those URLs would be easily generated by a routing helper.
The solution given in this answer
does not work anymore in Rails 3....
23
votes
4
answers
7k
views
Rails - Where (directories) to put Models that are not Active Record
We are building out apps that have Models that are not database components.
We are curious to learn what others are doing in the rails community to address this subject.
We are struggling with where ...
23
votes
7
answers
10k
views
Rails: validate presence of parent_id in has_many association
I have a projects resource that has many tasks. I want to ensure that every task has a project_id by adding validates_presence_of :project_id to the tasks model.
However, when creating a new project ...
23
votes
2
answers
15k
views
Yii: validation rules that always apply except one scenario
I know that you can have a validation rule that applies only for one scenario:
array('username', 'exist', 'on' => 'update'),
Now i would like to know if it's possible to do the opposite: a rule ...
23
votes
1
answer
12k
views
How do Django Fixtures handle ManyToManyFields?
I'm trying to load in around 30k xml files from clinicaltrials.gov into a mySQL database, and the way I am handling multiple locations, keywords, etc. are in a separate model using ManyToManyFields.
...
23
votes
2
answers
13k
views
Can you add parameters to Django custom admin actions?
For example (not the case, but just to illustrate) if I wanted to add an action to set a specific field in the selected items to X. Is it possible to add an action to allow X to be entered as opposed ...
23
votes
1
answer
7k
views
Django: Generate slug field data for existing entries in database
Some time ago I created a Django model:
class Product(models.Model):
name = models.CharField(verbose_name=_('Nome'), max_length=100)
description = models.CharField(verbose_name=_('Descrizione'...
22
votes
4
answers
29k
views
django temporarily disable signals
I have a signal callback in django:
@receiver(post_save, sender=MediumCategory)
def update_category_descendants(sender, **kwargs):
def children_for(category):
return MediumCategory....
22
votes
6
answers
6k
views
What's the best way to attach behavior to a Meteor Collection?
In Meteor, when you retrieve a record from a database, it's only a record. So if I have a collection called Dogs, a dog might have fur: 'brown' or breath: 'stinky', but it doesn't have a bark() method....
22
votes
1
answer
12k
views
Recursively including all model subdirectories
How do you load all directories recursively in the models and lib directories? In application.rb, I have the lines:
config.autoload_paths += Dir[Rails.root.join('app', 'models', '{**}')]
config....
22
votes
2
answers
14k
views
Ruby on Rails: How to validate a model without Active Record?
I'm currently trying to validate fields without having an ActiveRecord::Base inheritance.
My model stores the data on a cache server so I do not need ActiveRecord.
Anyway, I would like to validate the ...
21
votes
11
answers
3k
views
Is there any Mathematical Model or Theory behind Programming Languages? [closed]
RDBMS are based on Relational Algebra as well as Codd's Model. Do we have something similar to that for Programming languages or OOP?
21
votes
3
answers
17k
views
Rails: categories and sub-categories model rails
Without using any gems how do I do this in rails?
Main Category
Sub Category
Sub Category
Sub Category
Main Category
Sub Category
Sub Category
Sub Category
Main Category
Sub Category
...
21
votes
3
answers
16k
views
Laravel: Whenever I return a model always return a relationship with it
I have 2 tables:
User | Doctor
---------- | ----------
id | id
email | user_id
name | signature
last_name | photo
password | description
date_birth |
...
21
votes
1
answer
60k
views
how backbone.js model fetch method works
i am very confuse about using backbone.js model fetch method. See the following example
backbone router:
profile: function(id) {
var model = new Account({id:id});
console.log("<---------...
21
votes
1
answer
6k
views
Django models: mutual references between two classes and impossibility to use forward declaration in python
I have defined two models where each one references the other, like so:
class User(models.Model):
# ...
loves = models.ManyToManyField(Article, related_name='loved_by')
class Article(models....
21
votes
4
answers
18k
views
How to assign items inside a Model object with Django?
Is it possible to override values inside a Model?
I am getting 'MyModel' object does not support item assignment.
my_model = MyModel.objects.get(id=1)
print my_model.title
if my_model.is_changed:
...
21
votes
3
answers
22k
views
SQLAlchemy - order_by on relationship for join table
I'm using declarative SQLAlchemy and I have three models: Role, Permission, and RolePermission. In my Role model, I have the following:
class Role(Base):
name = Column(u'NAME', VARCHAR(50), ...
21
votes
2
answers
13k
views
Check if Model is valid outside of Controller
I have a helper class that is passed an array of values that is then passed to a new class from my Model. How do I verify that all the values given to this class are valid? In other words, how do I ...
21
votes
5
answers
10k
views
Backbone JS: how to disable sync for delete?
I am dealing with a threaded comments collection, and when I delete a comment that has children, I do model.destroy() for this comment, and on the server side all its branches get deleted.
I wrote a ...
21
votes
2
answers
5k
views
How to determine if a table relationship is bidirectional or unidirectional in Doctrine 2?
I am in the process of upgrading from Doctrine 1.1.4 to Doctrine 2.0.6 in my Zend application.
Currently, I am working on mapping the associations between entities. In Doctrine 2's Documentation it ...
21
votes
4
answers
9k
views
ForeignKey to abstract class (generic relations)
I'm building a personal project with Django, to train myself (because I love Django, but I miss skills). I have the basic requirements, I know Python, I carefully read the Django book twice if not ...
21
votes
4
answers
26k
views
Laravel Generate Migration from existing Model
How can I create migration file from existing model in Laravel or model from existing migration?
21
votes
1
answer
32k
views
How to animate a 3d model (mesh) in OpenGL?
I want to animate a model (for example a human, walking) in OpenGL. I know there is stuff like skeleton-animation (with tricky math), but what about this....
Create a model in Blender
Create a ...
20
votes
4
answers
32k
views
difference between models and view models
I have been researching asp.net MVC project structure's for a new project and have a question about something is confusing me. What is the difference between models and view models? Would I be correct ...
20
votes
5
answers
39k
views
Ruby on Rails - Access controller variable from model
I am trying to access an instance variable which is set in the controller in the model. The controller is the products controller and the model is the products model. The instance variable is a ...
20
votes
4
answers
16k
views
How to override a column in Rails model?
I have a model for one of my database tables. I want to override the column name for that particular table. How would I achieve it.
For example, let my table be called DUMMY and it has one column ...
20
votes
3
answers
11k
views
Rails: is it possible to add extra attribute to a has_and_belongs_to_many association?
What I mean is if I have two models, connected by a has_and_belongs_to_many association, can I store other data in the join table for each association? That is, the extra data would not be part of a ...
20
votes
2
answers
12k
views
Default filter in Django model
Is is possible to set a default filter in Django models?
Something like:
class MyModel(models.Model):
timestamp = models.DateTimeField(default=datetime.utcnow)
active = models.BooleanField(...
20
votes
2
answers
17k
views
Django: Grab a set of objects from ID list (and sort by timestamp)
I have a list of IDs for objects that I need to grab, then I have to sort them by their timestamp. Here's how I was going to do it:
For i in object_ids:
instance = Model.objects.get(id = i)
# ...
20
votes
4
answers
24k
views
Cannot skip validation in Rails 3?
I'm working on a project in Rails 3 where I need to create an empty record, save it to the database without validation (because it's empty), and then allow the users to edit this record in order to ...
20
votes
1
answer
8k
views
django model CharField: max_length does not work?
I'm trying to make a field with limited choices:
Action_Types=(
('0','foo'),
('1','bar'),
)
class Foo(models.Model):
myAction=models.CharField(max_length=...
20
votes
2
answers
35k
views
Destroying a Backbone Model in a Collection in one step?
Are these two steps mandatory to delete a Model?
var model = collection.get(id);
model.destroy();
collection.remove(model);
Isn't there a way to destroy a model when it is removed from its ...
20
votes
4
answers
23k
views
ASP.NET MVC View Model Naming Conventions
I know I will probably get a mixed opinion on this, but I was wondering if there were and "Best Practices" for model naming conventions.
I have a rather large application and I have adopted the ...
20
votes
3
answers
51k
views
Import data from excel spreadsheet to django model
I'm building a website that'll have a django backend. I want to be able to serve the medical billing data from a database that django will have access to. However, all of the data we receive is in ...
20
votes
4
answers
22k
views
Can you access a model from inside another model in CodeIgniter?
I am writing a webapp using CodeIgniter that requires authentication. I created a model which handles all my authentication. However, I can't find a way to access this authentication model from inside ...
20
votes
4
answers
31k
views
Compare two lists of object for new, changed, updated on a specific property
I've been trying and failing for a while to find a solution to compare to lists of objects based on a property of the objects. I've read other similar solutions but they were either not suitable (or I ...
20
votes
3
answers
19k
views
Difference among Model, javabean and POJO
I started learning MVC with spring. I have heard lot of time Bean, that contains setter and getter. Model is basically what data flows around, and Pojo which is same as Bean. But I am really confused ...
20
votes
5
answers
14k
views
Modeling objects with multiple table relationships in Zend Framework
I'm toying with Zend Framework and trying to use the "QuickStart" guide against a website I'm making just to see how the process would work. Forgive me if this answer is obvious, hopefully someone ...
19
votes
4
answers
9k
views
Overriding default_scope in Rails
In my Post.rb model, I have default_scope :conditions => {:deleted => 'false'}
But if I try to run Post.find(:all, :conditions => "deleted='false'"), it won't return anything. It's as if ...