model

SQLAlchemy context sesitive function for creating a composite value on insert and update

I'm trying to sort out how to add a context sensitive function (e.g. def get_user_full_name()) that will get triggered from the default and onupdate specifications on a column. I'm trying to set a composite field that combines the first and last names into a single full name value to avoid having to constantly concat the two fields in a...

How to deploy customer-specific functionality

I have a domain-specific application that is used by a few customers. The customers each have their own specific requirements. Sometimes extra fields, sometimes different rules and funcitonality. The domain objects change very little but the customer. Because the domain objects are fairly static I opted for anemic domain model with fi...

Return a model from a custom query without hitting the database

Hi, I have a custom query which eventually returns a list of objects. I need the function to return the actual objects but I don't want to hit the database twice for every query since it's already an expensive query. How can i return a model instance without hitting the db? NB: I presume doing something like the following will actually...

Looking for a Java framework that allows end users to extend the data model at runtime

Is there a Java framework that allows me to extend the data model at runtime with new fields and maybe even classes? Ideally, non-Java people should be able to do that (i.e. with a config dialog). ...

How do I create a blacklist/whitelist for finding Rails model records?

I want to create a model, "Whitelist" to build a list of users that I do not want displayed in my main model, "User". Example Controller def index @users = User.find(:all) #These are to be filtered behind the scenes in the model end Example Model class User ActiveRecord::Base has_many :whitelist def self.find #Add somethi...

iPhone MVC. Problems with the model.

I'm new to programming, iphone application programming in specific. After reading a bunch about MVC I decided to give it a try in a small application. As to my understanding, MVC works like this: Model: data, manipulating data, retrieving data. ViewController: formats data from the model (NSDate to specific style), etc. View: the actu...

multiple ->select() in doctrine query

Hi, for a doctrine model I'm making I don't always need to fetch all the columns I was hoping that I could solve this using $query = Doctrine_Query::create() ->select('a'); if(!empty($value)){ $query->select('b'); } $query->execute(); but this does not work... Does anyone have a clue how this could be done? ...

Missing method '%' using has_many and find() in Rails

I'm getting a very odd error when I attempt to access the find method of a has_many relationship. What am I doing wrong syntactically? # Instructor model class Instructor < ActiveRecord::Base has_many :events end # Event model class Event < ActiveRecord::Base belongs_to :instructor end # Controller snip-it i = Instructor.first co...

django not taking in consideration model fields declared in __init__

Hi, When using Model class like this: class MyModel(models.Model): def __init__(self, *args, **kwargs): self.myfield = models.Field() super(MyModel, self).__init__(*args, **kwargs) It doesn't take into consideration myfield(in the admin form, when saving the object... ) But if i declare like that: class MyModel(m...

KO3: Pretend properties on a Kohana_ORM Model

Say I have a very simple model that looks like this: class Model_Person extends ORM { /* CREATE TABLE `persons` ( `id` INT PRIMARY KEY AUTO_INCREMENT, `firstname` VARCHAR(45) NOT NULL, `lastname` VARCHAR(45) NOT NULL, `date_of_birth` DATE NOT NULL, ); */ } Is there a way I can I add sort of a pretend property with...

UML class modeling of callback functions/classes

I'm no expert in UML, I just took a course before I graduated that spent a significant amount of time on UML modeling. I understand the basics but I was working on a project the other day and just for my own curiosity, I was wondering how you would model a callback. Here is a portion of the code I was working on class OnChangeHandler...

Show latest posts all from unique tags (Rails 3.0, Acts_As_Taggable_On)

tags_controller.rb: def index @title = "tags" @posts = Post.tag_counts.collect do |tag| Post.tagged_with(tag).first(:order => "updated_at DESC") end @posts.uniq! end tags/index.html.rb: <%= render 'latest' %> _latest.html.erb: <%- for post in @posts -%> <%- post.tags.each do |t| -%> <%= link_to t.name, tag_path(t...

Data model, cyclic references

I have the following data structure for storing meridians and parallels. Each cartographic point stores: A] geographic and spatial coordinates, cartographic distortions, etc. B] pointer to north/south/east/west node. It allows to store relationships between points, first of all their affiliation to the meridian/parallel... class...

In Rails models, can I change belongs_to to has_one and has_one to belongs_to?

Hi, If I have two models. Model1 belongs_to Model2, and Model2 has_one Model1. Thus I can access Model2 from Model1 as well as Model1 from Model2. Now my question is, can I change the relationship to Model2 belongs_to Model1 and Model1 has_one Model2? It also can let me traverse from Model1 to Model2 and from Model2 to Model1. I'm not s...

Reading models into ViewModels and other way round in MVVM - best practice -

Hello guys, I would like to get an insight into your daily work :P How do you read the Person data into the PersonViewModel ? Is it just a PersonViewModel pVM = staticHelper.ConvertPersonToPersonViewModel(person); or is there something cooler? ...

Specifying a different model than the controller name suggests

Guys, I've got a controller called "ResourcesController", but its really managing the CRUD for two different models. I don't actually have a model called Resource, so the controller is balking that it can't find it. Is there a way I can inform the controller which model I'll be working with so it doesn't freak out? The error that is ...

Doctrine 1.2: Defining conditions on relationships

I'm trying to define conditions on relationships with Doctrine. Is it possible? I mean something like this: class User extends Doctrine_Record { public function setUp() { $this->hasMany('Article as ReallySpecialArticles', array( 'local' => 'id', 'foreign' => 'user_id', 'conditions' =...

[Django] Insert params into database as full object?

hi, un rails i can simply insert the params into the database with one command, when all form-field names are the same like the model-field names. is this possible in django as well, or do i have to set each param individually. i have like 20 fields, so it's a bit of a mess.. :) something like: blah = Contact() blah.content = params[]...

ASP MVC DateTime problem model validation problem

I have MS SQL in my local development server and production server. The DateTime format of my local server is "mm/dd/yyyy" but the format in production server is "dd/mm/yyyy". Every thing worked fine in my local server , but when I try to enter a date like "05/31/2010" in my production server, the Model Validation threw an error "The va...

get current variable Rails, in before_save

Is there a way to get the current variable? lets say that i have a "title" attribute in a method and i want to check in with the old value of the variable ? how could i accomplish this ? ...