model

City belongsThroughCountyTo Province association, how to simplify the code?

Tables: Province hasMany County, County belongsTo Province, County hasMany City, City belongsTo County So basically something like: City belongsThroughCountyTo Province Situation: In a search form I have a select drop down menu with provinces. The "code": When I list the results, I first get ids of counties that belong to the speci...

How can I dynamically determine which model a controller is controlling?

I'm writing a Rails plugin, and need to be able to dynamically determine which model a controller is associated with. For example, if I have a PeopleController, I need a clean way to determine that the controller handles Person models. I've had a look through the API and haven't found a method for it. Is the only way to do this as a re...

Zend Framework model with service

Hi, i have a question about Zend Framework and mainly the model part. I know there is no abstract model class and understand why. I red a lot of blog posts about it, but couldn't find any example that would clearly explain it to me. I'm building a very basic application. Lets imagine we have just three tables. company(ID, name, street, s...

Dynamically update ModelForm’s Meta class model field

def SiteAdminForm(model_cls, *args, **kwargs): class MerchantAdminForm(forms.ModelForm): class Meta: exclude = ('external_links', 'published', 'logo','image_zip_file',) model = model_cls def __init__(self, *args, **kwargs): super(MerchantAdminForm, self).__init__(*args, **kwargs) ...

How do I use a custom helper method from a model in Rails?

There is a helper method in my custom helper module EntriesHelper that I need to use from inside a model. I watched the Railscasts episode Helpers Outside Views and learned about ActionController::Base.helpers, but this only gives you access to the built-in helpers. I don't want to simply include EntriesHelper in the model because of nam...

problems or flaws of the asp.net postback model

There are several talks about this issue, but I havent found a clear complete explanation of the flaws of the postback model in relation with other models. If you think this is a redundant question, and you are tired of these topics I'll understand you vote to close it but what I usually read in articles in internet and here it's the pos...

ASP.NET MVC - Model Validation regarding its dataType Length

Hello there, I'm using ASP.NET MVC 1 on a project where I would like to validate my form submission with the ModelBinding helpers, actually I am validating it with ModelState.IsValid but it doesn't seem to consider the dataType length when validating it. For example: I have a field nvarchar(70) called Name , but when in my form I submi...

How to get the object with its translation using getRoute in Symfony?

I have several models with translations. When I load $this->tour = $this->getRoute()->getObject(); por example, it gets me the Tour Object. However, it doesn't join to the tour_translation table; so when after i try to get it's title; symfony makes another sql query. How I can override something, so in the Tour model when I ask for t...

Rails .scan won't work with a model variable using nokogiri

Hello, I 'll try to be as explicit as possible I am using nokogiri to parse links from paths and rules out of a database I have this model: --- !ruby/object:Content attributes: id: "2" name: http://www.****** try description: try url_base: http://www.****** scan_flv: /"file","([^<>]*flv)"\);/imu source_site_id: "2" con...

Binding a QT model to an existing data-structure

I've a tree-like polymorphic data-structure, where the nodes are instances of class Node (implemented by me) or any its subclass. My application heavily uses Boost and the nodes are actually represented by boost::shared_ptr type rather than Node*. Now, I want to create a QT model to wrap my tree data-structure. Therefore I need a way to...

Need a self. method on a Rails model using Acts_as_list

I am still newer to Rails... I need to write a self.method on my Product model to find the next Product per position. I am showing 1 Product on a page, and want the next one in the list. def self.next_product product = Product. # current product.position +1 end obviously this won't work... I am still new to writing methods. anyone? ...

Smarter paperclip validations

I'm using paperclip in a rails app and have the following three validations in my model validates_attachment_presence :photo validates_attachment_size :photo, :less_than=>1.megabyte validates_attachment_content_type :photo, :content_type=>['image/jpeg', 'image/png', 'image/gif'] If the user forgets to add an attac...

validates_presence_of + :message shows the name of the field

Hello, I'm creating a Rails app, and I have a model called User. In this model I have a boolean value called isagirl. A user must specify if it is a girl or not, which is done by two radio buttons. In my model I have this: validates_presence_of :isagirl, :message => "You must be either a Boy or a Girl. If not, please contact us." How...

Model Validation problem in ASP.NEt MVC 2 RC 2

Hi, I have facing the following problem after the update. I have a Model with Class level Validation plus property level validation in it. After updating to MVC 2 RC 2. The model validation fails on Model binding. What i actually understand that new mechanism trying to validate the model when you first request it or say on GET and it ge...

How do I validate that two values do not equal each other in a Rails model?

I have a User model, which has an email and a password field. For security, these may not be equal to each other. How can I define this in my model? ...

[R] plot line over last part of barplot

I have a barplot for which the second half should fit to this formula: y~a*x*exp(-b*x^2). Now I want to plot the entire barplot and display the fitted model over the last part of the barplot as it only holds for that part. However, I cannot find a way to display the line-graph only over the second half. If I just do something like subm...

How do I pass multiple model IDs into comments add action in CakePHP?

My question concerns how I can use one comments controller with multiple 'belongs to' controllers. I want to add comments to news, posts, and matches (it's a tennis website). I've got the comments add action setup to use the 'ajax' helper and I'm also using counterCache to keep track of the number of comments for each news, post and mat...

DataMapper and Codeigniter - how to fully manage a many-to-many relationship

I have the following relationship CType has many Field Field has many Ctype and of course the tables used are fields, ctypes, and ctypes_fields. Normally, the ctypes_fields table should contain only ids referencing the other two tables. However, i'd like to put there a "options" field that will contain some content for the concrete in...

Is there any algorithm for projecting images onto a non-flat surface?

Is there any algorithm for projecting images onto a non-flat (deformed) surface? It is not deformed too much. It is a really glassy surface covered with high-quality, durable tracing paper. I have a 3-dimensional model of it. How can I texturise it with a projector? I want to write a program in C\C++\C# for Windows, which would be ...

Best practices for an API in PHP : functions, or classes ?

Hi, In my company we have developped some applications. We have to create an API for one application (say application A), so that the others can use it (an its data). The question is : we already have developped PHP classes for the model of Application A, if we want to create an API, should we : - re-use these classes (too much functio...