Questions tagged [model]

Part of the MVC pattern, the Model manages the behaviour and data of the application.

Filter by
Sorted by
Tagged with
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 ...
user1482228's user avatar
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 ...
the_drow's user avatar
  • 19k
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 ...
ajameswolf's user avatar
  • 1,650
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 ...
Roy Prins's user avatar
  • 2,940
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 ...
Ami's user avatar
  • 515
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 ...
Jack's user avatar
  • 9,693
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 ...
cretzel's user avatar
  • 20k
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 ...
user2276094's user avatar
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 ...
Synthead's user avatar
  • 2,272
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 ...
warakawa's user avatar
  • 628
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....
Florent2's user avatar
  • 3,483
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 ...
Michael Durrant's user avatar
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 ...
deb's user avatar
  • 12.6k
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 ...
darkheir's user avatar
  • 8,900
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. ...
CMaury's user avatar
  • 1,283
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 ...
nickponline's user avatar
  • 25.6k
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'...
marco.santonocito's user avatar
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....
bartek's user avatar
  • 2,961
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....
Samo's user avatar
  • 8,210
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....
GTDev's user avatar
  • 5,498
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 ...
Nicolas Guillaume's user avatar
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?
Padmarag's user avatar
  • 7,135
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 ...
Ollie2619's user avatar
  • 1,265
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 | ...
Mathius17's user avatar
  • 2,482
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("<---------...
softshipper's user avatar
  • 33.3k
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....
koo's user avatar
  • 2,908
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: ...
Pompeyo's user avatar
  • 1,469
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), ...
Sarah Vessels's user avatar
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 ...
James Santiago's user avatar
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 ...
mvbl fst's user avatar
  • 5,243
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 ...
Mr B's user avatar
  • 4,090
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 ...
pistache's user avatar
  • 6,003
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?
Ники Арсов's user avatar
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 ...
user2602528's user avatar
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 ...
amateur's user avatar
  • 44k
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 ...
RailsSon's user avatar
  • 20.3k
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 ...
bragboy's user avatar
  • 35.3k
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 ...
David Robertson's user avatar
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(...
SimonSays's user avatar
  • 10.9k
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) # ...
Goro's user avatar
  • 10.1k
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 ...
Andrew's user avatar
  • 42.8k
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=...
Xun Yang's user avatar
  • 4,269
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 ...
yves amsellem's user avatar
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 ...
Sam's user avatar
  • 15.6k
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 ...
TechEmperor95's user avatar
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 ...
Eldila's user avatar
  • 15.6k
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 ...
user3313496's user avatar
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 ...
Varun's user avatar
  • 4,422
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 ...
Andy Baird's user avatar
  • 6,120
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 ...
Jess's user avatar
  • 3,141

1
3 4
5
6 7
430