model

OO Design / Patterns - Fat Model Vs Transaction Script?

Ok, 'Fat' Model and Transaction Script both solve design problems associated with where to keep business logic. I've done some research and popular thought says having all business logic encapsulated within the model is the way to go (mainly since Transaction Script can become really complex and often results in code duplication). Howeve...

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_<attribute>(:<attribute> => "") 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 between Group and Member called GroupMember. I could have many instances where member_id ...

Filtering model results for Django admin select box

I just started playing with Django today and so far am finding it rather difficult to do simple things. What I'm struggling with right now is filtering a list of status types. The StatusTypes model is: class StatusTypes(models.Model): status = models.CharField(max_length=50) type = models.IntegerField() def __unicode__(self)...

Implementing a Cakephp Model using an Array

The CakePHP Cookbook states that a Model can use a file (csv for example) instead of an actual database table but I couldn't find any implementation for it. I was wondering if it is possible to use an Array of data as a model in CakePHP since I have a fairly static set of data which is important to me in a relationship with another tabl...

Cakephp change model's title without rename model/dbtable

I have a table that store all information about class, but because Class is reserved for class name I had to rename the table from classes to types. But in the view section I need it to be displayed as "Class", including the Paginator links. Anyway to achieve this by adding something in the Type model, without completely customize Pagi...

Django m2m adding field in the secondary table

I have a model in wich i'm using m2m Django ORM feature, in order to create an aditional table to hold my 'classrom members'. My problem is: the membership to a classroom must be accepted by the invited one, so i need a boolean field :1=accepted, 0=refused/unseen yet. How can i include this boolean variable in the aditionally generated c...

How do I initialize attributes when I instantiate objects in Rails?

Clients have many Invoices. Invoices have a number attribute that I want to initialize by incrementing the client's previous invoice number. For example: @client = Client.find(1) @client.last_invoice_number > 14 @invoice = @client.invoices.build @invoice.number > 15 I want to get this functionality into my Invoice model, but I'm not ...

symfony 1.4: doctrine build model warning

Hi volks, I copied my sources from my lokal dev (everything works fine) to my repository and from there I did a checkout on my remote dev. Now when I try to build everything I get this error: devel:/var/www/myproject# ./symfony doc:build-model doctrine generating model classes file+ /tmp/doctrine_schem...

What's the correct place to share application logic in CakePHP?

I guess simple answer to the question would be a component. Although I agree, I feel weird having to write a component for something so specific. For example, let's say I have a table of users. When a user is created, it should form a chain reaction of events, initiating different kinds of data related to the user all around the databa...

Multiple has_manys of the same model

I have these models: Person has_many :messages_form_person, :foreign_key => :from_user_id, :class_name => :messages has_many :messages_to_person, :foreign_key => :to_user_id, :class_name => :messages Message belongs_to :to_person, :foreign_key => :to_user_id, :class_name => :person belongs_to :from_person, :foreign_key => ...

How to message an object?

I am working in objective-C trying to write an iphone app. Background: There is a navigation controller managing my view controllers. My FirstLevelViewController on viewDidLoad creates a few SecondLevelViewController Objects, stores them in an array, and then loads them when various table cells are pushed. In addition, on viewDidLoad,...

How to access model in jquery

Hi, The question here is very simple This is my view <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<GetmoreRevamp.BAL.Product>" %> <link href="<%=Url.Content("~/Content/AddToCart.css")%>" rel="stylesheet" type="text/css" /> <link href="<%=Url.Content("~/Scripts/jquery-1.4.1.js")%>" type="text/javascript...

Basic question about interface

Hi, I get answer in: http://stackoverflow.com/questions/3084125/object-modelling-problem that I should use interface instead class Extra in this case: public Extra { public bool Paid {get;set;} public string Name {get;set;} public string Code {get;set;} } class Car { private List<Extra> _listOfExtras=new List<Extra> public List<Ext...

Rails Multi Model 'Primary Key' Validation

Hello, I have three models, say Item, Category, Label. Item can have one Category and many Labels, however each Item record must have a unique combination of Category and/or Labels. I'm using Rails 2.3.5, what is the best way to ensure this integrity? Thanks! ...

Bestpractice - Mixing View Model with Domain Model

Is it reasonable to mix view models with domain models? So i.e. the view model object contains some domain model objects (not the other way around!) ...

DRYing ASP.NET MVC controllers and views

How do I share code among controllers of different models. In a 'super' controller action, I want to be able to figure out which controller (route) was called, and using that route name load the corresponding model, and use that model to query the database to pass to the view. I can easily do this in Ruby on Rails, does MVC allow such ...

Having an issue with custom Qt ItemModel

I'm trying to create a model to store data about photos, icons and pathnames. class PhotoListItemModel : public QAbstractItemModel { struct ItemModelType { std::string fileName; QImage image; boost::shared_ptr<char> unique_id; }; std::map<string, ItemModelType> ItemMap; std::map<char*, stri...

django store incremental numeric values in a table?

i want to make a rank application, that will calculate the rank of each course uploaded on a platform. Is it a good approach to have stored in a table values like number of downloads, and number of views, like that? class Courserate(models.Model): course = models.ForeignKey(Courses) downloads = models.IntegerField(editable = F...

Understanding Scrum

I have been working as a .net developer following waterfall model. When working on, say a 12 months project, usually my team follows Analysis, Design, Coding and Testing phases. But when it comes to following Scrum process, I don't really understand How I need to deal with it. Consider a sprint for 4 weeks and our backlog has 10 items, ...

Rails: accessing field value from model method

Just started learning Rails (3). I am tearing my hair out trying to find how to do something presumably utterly trivial: access the value of a model instance's field, from inside a method on that model. In my case: def formal_name @title + " " + @forename + " " + @surname end All three @properties (which are all fields on the tabl...