model

Python/Django Modeling Question

What is the best way to have many children records pointing to one parent record in the same model/table in Django? Is this implementation correct?: class TABLE(models.Model): id = models.AutoField(primary_key=True) parent = models.ForeignKey("TABLE", unique=False) ...

Overengineering - How to avoid it.

Sometimes I find myself designing my classes for a certain project. I start with some entities, some interfaces, but after some time I think: Hey what about creating a handler for the classes using a Factory Method, Strategy, Using Generics, etc, etc, etc. At some point when I look to my classes I have a lot of generics, small objects,...

Lazy setting of model attributes in Rails?

I have a model which is generated by parsing a data file. There are several interesting values which are not present in the original data file but can be derived from the ones that are. However, many of these derived values are expensive to compute, so I would like to store them in the database once they have been computed. I have trie...

Cakephp - checkPasswords is always false

Hello :) I'm working on the signup process and want to check if the two passwords (password + re-entered password) are equal. These are my validation rules in the User Model: var $validate = array( 'username' => array( 'notEmpty' => array( 'rule' => array('minLength', 5), 'required' => true, ...

Mixing security logic with models in Ruby on Rails?

Is it bad design to mix code that deals with security logic in the model? Example for editing a page in the before_save callback The current user is grabbed from the current_user method in the Controller layer. Throw exception if current_user.has_permission? :edit_page is false The editor_id is set to current_user.id The change is log...

sql join or calling another model?

I have two tables (item and category, I think they speak for themselves) and two associated model objects. I'm facing a design decisions in the function that fetches 1 item from the database. I need this method to also return the category (name, not just id) of the item. I have two options: In the item model, use an SQL join to get th...

Is a Repository still a Repository without Unit of Work?

If you create a repository class that encapsulates all of your persistence logic for a given entity, such as PersonRepository, but your repository class does not implement the Unit of Work pattern or the Identity Map pattern, is it still considered a repository? In other words, are Unit of Work and Identity Map required for a repository...

Globalization with NHibernate

How would you build your domain objects and create its respective NHibernate mapping files for a multi language application. The UI part is stored in resource files but user data needs to go into the database. I want to do the following: Product p = DALProduct.getByID(2) p.name //results in the language of the current UICulture I hav...

How to compare value of 2 fields in Django QuerySet?

I have a django model like this: class Player(models.Model): name = models.CharField() batting = models.IntegerField() bowling = models.IntegerField() What would be the Django QuerySet equivalent of the following SQL? SELECT * FROM player WHERE batting > bowling; ...

How to put timedelta in django model?

With inspectdb I was able to get a "interval" field from postgres into django. In Django, it was a TextField. The object that I retrieved was indeed a timedelta object! Now I want to put this timedelta object in a new model. What's the best way to do this? Because putting a timedelta in a TextField results in the str version of the obje...

When I have required model relationships, how do I guard against errors?

I have an application with a lot of database relationships that depend on each other to successfully operate the application. The hinge in the application is a model called the Schedule, but the schedule will pull Blocks, an Employee, a JobTitle, and an Assignment (in addition to that, every Block will pull an assignment from the databas...

Getting the username inside a model class

I'm trying to implement basic auditing with some of my models (like CreatedAt, UpdatedAt, CreatedBy and UpdatedBy). The date/time part is done. I'm throwing events on my models when a property is changed (implementing INotifyPropertyChanging, INotifyPropertyChanged) and can update the correspondent fields just fine. I just need to know...

booleans in rails with sqlite

I am a bit of a noob still with rails, but I am running across something that seems a bit odd. I added a boolean field to a model in the database thusly t.column :admin, :bool, :default => false, :null => false However, the value in the sqlite3 database seems to be either 't' or 'f'. That is fine, but I would still expect user.admin? ...

NHibernate Mapping File Help

Hi All NHibernate noob here. Looking for advice on how to map the following common scenario: [Store] id pk Name [StockItem] id pk Name [StockItemStore] id pk StockItemId fk StoreId fk ParLevel I have created a domainmodel that allows various StockItems to be assigned to various Stores via the StockItem Entity using a AssignToStore(S...

Rails Partial Image Rendering

Hey everyone, I'm getting up to speed on rails and ran into an odd problem. I'm rendering some images from the database (Image models attached to another model, Plants). I'm having some trouble when attempting to do it via a partial. I've got show.html.erb <fieldset class="fieldset"> <legend>Images</legend> <%= unle...

In MVC, does an ORM represent the model?

In MVC, is the ORM the same as the model or just a way the model can be designed? In other words, the "model" doesn't care how you get data as long as you get it. Or, does "model" imply that I no longer have a bunch of SQL statements in my code like in code behind forms? Something else? Thank you. ...

GETing different Active Resource models in a single request

Hi! Is it possible to receive objects of different Active Resource models in a single request? For example the request "GET /user/joe/articles/1.xml HTTP/1.1" returns an object from User ("joe") and another object from Article (id "1") from the server. I know it is possible to send these objects inside an array to the client, but ARes ...

Is the Rails update_attributes method the best choice for doing an update of a model in the database?

def update @album = Album.find(params[:id]) if @album.update_attributes(params[:album]) redirect_to(:action=>'list') else render(:action=>'edit') end end A Rails 1.1.6 tutorial that I'm covering recommends using the update_attributes method for updating a model, as in the example code from my controller listed above. L...

Not sure where (model or controller) to define my find method

(Warning: Clueless Rails Newbie!) In my show.html.erb for my albums view, I call a public method in my albums controller: <% albums_feature = find_albums_with_feature(feature.id) %> It generates a NoMethodError. So I copied the method into my Album model and tried calling it from the view as: <% albums_feature = Album.find_albums_w...

How can I do this without breaking the MVC framework in CakePHP?

Sorry for what is a generic title. I'm not the best at titles. Anyway the way Cake passes around data (as a hash) is pretty much the reason why I even need to ask this question. If when I passed a variable/obj from the controller to the view, it was an object that I can ask questions to (i.e. $duck->quack() ) rather than having it be an...