Questions tagged [model]

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

The MVC (Model, View, Controller) pattern separates objects into one of three categories — models for maintaining data, views for displaying all or a portion of the data, and controllers for handling events that affect the model or view(s).

Frameworks such as Laravel, Rails, Django and ASP.NET MVC apply this pattern in the web development domain.

18996 questions
576
votes
5 answers

How should a model be structured in MVC?

I am just getting a grasp on the MVC framework and I often wonder how much code should go in the model. I tend to have a data access class that has methods like this: public function CheckUsername($connection, $username) { try { …
Dietpixel
  • 9,983
  • 11
  • 28
  • 33
426
votes
16 answers

Get Android Phone Model programmatically , How to get Device name and model programmatically in android?

I would like to know if there is a way for reading the Phone Model programmatically in Android. I would like to get a string like HTC Dream, Milestone, Sapphire or whatever...
Andrea Baccega
  • 27,211
  • 13
  • 45
  • 46
372
votes
9 answers

Ignore mapping one property with Automapper

I'm using Automapper and I have the following scenario: Class OrderModel has a property called 'ProductName' that isn't in the database. So when I try to do the mapping with: Mapper.CreateMap(); It generates an exception : "The…
Msam85
  • 3,964
  • 2
  • 18
  • 18
293
votes
13 answers

Doctrine2: Best way to handle many-to-many with extra columns in reference table

I'm wondering what's the best, the cleanest and the most simply way to work with many-to-many relations in Doctrine2. Let's assume that we've got an album like Master of Puppets by Metallica with several tracks. But please note the fact that one…
Crozin
  • 43,890
  • 13
  • 88
  • 135
237
votes
29 answers

Is there a way to get a collection of all the Models in your Rails app?

Is there a way that you can get a collection of all of the Models in your Rails app? Basically, can I do the likes of: - Models.each do |model| puts model.class.name end
mr_urf
  • 3,303
  • 4
  • 26
  • 29
212
votes
4 answers

Rails :dependent => :destroy VS :dependent => :delete_all

In rails guides it's described like this: Objects will be in addition destroyed if they’re associated with :dependent => :destroy, and deleted if they’re associated with :dependent => :delete_all Right, cool. But what's the difference between…
Sergey
  • 4,702
  • 6
  • 26
  • 32
210
votes
5 answers

Rails find_or_create_by more than one attribute?

There is a handy dynamic attribute in active-record called find_or_create_by: Model.find_or_create_by_(: => "") But what if I need to find_or_create by more than one attribute? Say I have a model to handle a M:M relationship…
tybro0103
  • 48,327
  • 33
  • 144
  • 170
207
votes
7 answers

Determine what attributes were changed in Rails after_save callback?

I'm setting up an after_save callback in my model observer to send a notification only if the model's published attribute was changed from false to true. Since methods such as changed? are only useful before the model is saved, the way I'm currently…
modulaaron
  • 2,856
  • 3
  • 24
  • 28
206
votes
7 answers

AngularJS - Binding radio buttons to models with boolean values

I am having a problem binding radio buttons to an object whose properties have boolean values. I am trying to display exam questions retrieved from a $resource. HTML:
200
votes
47 answers

Cannot overwrite model once compiled Mongoose

Not Sure what I'm doing wrong, here is my check.js var db = mongoose.createConnection('localhost', 'event-db'); db.on('error', console.error.bind(console, 'connection error:')); var a1= db.once('open',function(){ var user = mongoose.model('users',{…
Anathema.Imbued
  • 3,271
  • 4
  • 17
  • 18
194
votes
10 answers

Accessing MVC's model property from Javascript

I have the following model which is wrapped in my view model public class FloorPlanSettingsModel { public int Id { get; set; } public int? MainFloorPlanId { get; set; } public string ImageDirectory { get; set; } public string…
Null Reference
  • 11,260
  • 40
  • 107
  • 184
142
votes
9 answers

Difference between interfaces and classes in Typescript

What is the different between Typescript Interfaces and Classes? When do I use a Class? When do I use Interfaces? What are the advantages of them? I need to create some kind of types for an http-request to my backend server (Doing it with Angular…
Emre Öztürk
  • 2,660
  • 4
  • 16
  • 19
141
votes
8 answers

ASP.NET MVC Yes/No Radio Buttons with Strongly Bound Model MVC

Does anyone know how to bind a Yes/No radio button to a boolean property of a Strongly Typed Model in ASP.NET MVC. Model public class MyClass { public bool Blah { get; set; } } View <%@ Page Title="blah" Inherits="MyClass"%>
brianstewey
  • 1,792
  • 3
  • 14
  • 14
131
votes
6 answers

How to query database by id using SqlAlchemy?

I need to query a SQLAlchemy database by its id something similar to User.query.filter_by(username='peter') but for id. How do I do this? [Searching over Google and SO didn't help]
user507220
129
votes
5 answers

what is difference between a Model and an Entity

I am confused to understand what is the meaning of this words: Entity, Model, DataModel, ViewModel Can any body help me to understanding them please? Thank you all.
amiry jd
  • 27,021
  • 30
  • 116
  • 215
1
2 3
99 100