models

Rails: Unable to initialize has_many :through association from within unit test using model class name

I've been struggling to understand why I can easily use seeds.rb to create new Users and their default associations, but when running individual a unit test causes errors. I've tried to get around calling 'Role' as it causes errors in the unit test. I am relatively new to unit testing, but have been using Rails for several years alread...

Singleton Models Doctrine

Can we have a model class which is singleton in Doctrine? For Singleton classes I should have a private/protected constructor....but this is not possible as I am extending a Doctrine class which has a public constructor You can argue about the use of the Singleton pattern when interacting with the DB, but just consider this scenario: ...

Cakephp Multiple Relations to the Same Model

I'm working on a real estate application, where one Home can be listed by either one or two Realtors. As such, I'm trying to follow the example given in section 3.7.6.7 of the Cake Cookbook. Here's what's going on in my Realtors model: class Realtor extends AppModel { var $primaryKey = $num; var $name = 'Realtor'; var $hasM...

How does one make models in Rails?

I've gone over the tutorial, used the scaffold command to make a model, etc. I noticed that it mentioned more experienced programmers would probably create all their models from scratch... What is the "appropriate" way to do so? If it's a simple answer and I'm just Googlin' the wrong keywords, I apologize in advance. ...

Drawing from an S3 through my photo model gets tangled.

I just migrated my server's photos to an S3. Everything seems to work swimmingly except one little catch. If a user chooses a photo from his existing media, the server returns a 500 error. I assume this is because it might still be either looking for it on my local, OR it doesn't draw from the photo model appropriately : a. From my loc...

Model Based Testing Tutorial with C# / .NET

Is there any C# .NET resource from where I can learn about how to write Model Based Tests ? using NModel or preferrably Spec Explorer ? just some basic tutorials on how to write MBT ? thanks ...

CakePHP Model Callback, specifically beforeDelete

I'm trying to execute some logic before deleting a field. I have some models that are dependent on the model being deleted, and I want to make sure that image files related to those dependent models are also deleted, but I'm a bit confused on how the model callbacks work. I know that I define the before Delete function in the model cla...

Set Django ModelForm visible fields at runtime?

I have a Django model: class Customer(models.Model): first_name=models.CharField(max_length=20,null=True, blank=True) last_name=models.CharField(max_length=25,null=True, blank=True) address=models.CharField(max_length=60,null=True, blank=True) address2=models.CharField(max_length=60,null=True, blank=True) city=models.CharField...

how does one load a model with a custom name in to a controller

I'm trying to access a model for global system settings. It should be loaded in almost every controller. The problem is I can't find any help on getting rails to load the dam thing. If this helps, the model is called Config and has two columns; 'key' and 'value' I come from a background in PHP. I remember codeigniter could load models ...

Zend Join Models

I have models of my tables and would like to do a join using a model as opposed to to a table. For example, instead of: $select = $this->select() ->from(array('p' => 'products'), array('product_id', 'product_name')) ->join(array('l' => 'line_items'), 'p.product_id = l.product_id', ->limit(20, 10); where I specify the table na...

What is the 'best way' or 'best practise' for communicating errors to the View from a service layer in MVC2?

I had issued with using a ModelStateWrapper in MVC 1 as described here: http://www.asp.net/mvc/tutorials/validating-with-a-service-layer--cs As much as I was able to test my application it still felt like there was a dependency/circular reference with the ModelState, the controller and the service layer. With the new DataAnnotation in M...

dropdownlist and 2 listboxes: FormModel - asp.net mvc 2 question

There is a form: "dropdownlist", "available items listbox" and "selected items listbox", button: Add. "dropdownlist" is filled with values. OnDropdownChange "available items listbox" is populated with the values taken from db (ajax request). User, using Add button, moves elements from "available items listbox" to "selected items listbox...

django dynamic FilePathField

class Project(models.Model): slug = models.SlugField(max_length=100) main_file = models.FilePathField(path="/home/mn/myfiles/%s" % slug) This code doesn't work, just illustrating what I'd like to do. I want to fill in FilePathField when object is accessed (ie. when it is updated in django admin, not when it's created). Is the...

Pulling Data From Multiple Tables in Django

I'm kind of new to Django and am having some trouble pulling from existing tables. I'm trying to pull data from columns on multiple joined tables. I did find a solution, but it feels a bit like cheating and am wondering if my method below is considered proper or not. class Sig(models.Model): sig_id = models.IntegerField(primar...

Zend_Db and Models

Currently I have about 40 models and whenever I have needed to do an insert its always just been on a single model, so I have been happy to just use my class model which extends Zend_Db_Table_Abstract class Model extends Zend_Db_Table_Abstract However, now one of my requirements is to read a CSV file and normalize it into my database....

How to model and track requirements towards a goal in PHP

I'm building a webapp using the Zend Framework, and I need to model logic or keep track of some logic that has to do with tracking progress towards a goal. Let me illustrate with a sample goal. USER Needs to Complete All Three of the following: A) Activity One B) Activity Two C) Activity Three USER Needs to Complete One ...

Set session variable inside plugin model

So I'd like to set/get a session variable from inside a plugin model that I've included to my project. I tried making a method (one getter one setter) inside the application_controller.rb but this did not work. Where can I make getter/setter methods so that a plugin model has access to them? ...

What happens to models with BelongsTo and hasOne relationship setup?

What happens when two models are associated with a belongsTo and a hasOne relationship at the same time? Does the framework detect this situation to avoid retrieving too much data? EDIT: CakePHP specifically, although what other frameworks do would be helpful, too. ...

Running Stored Procedures on a Report Services Model.

Hi I am designing an SQL Report Server Model, to replace a table that was used as a cut down version of the main database to report from. So the report will use the model to report from not the cut down database. I was wondering if there was quick and easy way to take the Stored procedures, that were used for 100+ report on the cut do...

Django user proxy models fast access

I have proxy model for user: class MyUser(User): class Meta: proxy = True How can i get it in templates without pass from view? can i get it only from request.user instance? I am using template context processor for this: def m_processor(request): from main.models import MyUser mu = MyUser.objects.get(id = reques...