model

How to access view model data in jquery?

In my html, I use Model.Subcontract.company How can I reference that data in my jQuery? ...

asp.net mvc equivalent of rails callback before_save

Hi i'm looking for a asp.net mvc callback for elaborate data before save a model. In rails there is before_save. Thanks ...

Implicit Memory Barriers

let's say i have variables A, B and C that two threads (T1, T2) share. i have the following code: //T1 //~~ A = 1; B = 1; C = 1; InterlockedExchange(ref Foo, 1); //T2 (executes AFTER T1 calls InterlockedExchange) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ InterlockedExchange(ref Bar, 1); WriteLine(A); WriteLine(B); ...

Can i use a model object directly in a find

I have the following models: student class teacher a student can have multiple classes, a class can have 0 or 1 teachers. I want to be able to call a method on the student to see if they have a specific teacher, and return true or false. The following code seems to work, but i thought it looked a bit long winded, having to compare eac...

Zend without Database

Hi, i googled for an hour now but maybe my Google-Fu is just too weak, i couldn't find a solution. I want to create an application that queries a service via JSON requests (all data and backend/business logic is stored in the service). With plain PHP it's simple enough since i just make a curl request, json_decode the result and get wha...

Dynamically Add DataAnnotations Attributes to a view model depending on value of fields in model

I have a class Lets say public class Customer { public int id; public string FirstName {get;set;} public string LastName {get;set;} public string JobName {get;set;} public double Salary {get;set;} } A grid shows all these customers on a page. However, depending on Customer selected say id=1 , I want FirstName to have a StringLengt...

Cakephp Insert Ignore Feature?

Is there a way to do an "insert ignore" in cake without using a model->query function? $this->Model->save(array( 'id' => NULL, 'guid' => $guid, 'name' => $name, )); Generates error: Warning (512): SQL Error: 1062: Duplicate entry 'GUID.....' for key 'unique_guid'...

Having trouble understanding some code (Ruby on Rails)

I posted a question awhile ago asking how I could limit the rate at which a form could be submitted from a rails application. I was helped by a very patient user and their solution works great. The code was for my comments controller, and now I find myself wanting to add this functionality to another controller, my Messages controller. I...

[Zend Framework] How to fetch data from another table within a Zend_Db model class?

I have two tables registries and names. Consequently, I have two model classes. I'm coding a method in registries model and I need to fetch all names in the names table/model. How'd I do it? Should a simple new Names() work? But, is it recommended? ...

Storing n-grams in database in < n number of tables.

If I was writing a piece of software that attempted to predict what word a user was going to type next using the two previous words the user had typed, I would create two tables. Like so: == 1-gram table == Token | NextWord | Frequency ------+----------+----------- "I" | "like" | 15 "I" | "hate" | 20 == 2-gram table == Token ...

Per instance dynamic fields django model

I have a model with a JSON field or a link to a CouchDB document. I can currently access the dynamic informaction in a way such as: genericdocument.objects.get(pk=1) == genericdocument.json_field['sample subfield'] instead I would like genericdocument.sample_subfield to maintain compatibility with all the apps the project currently sh...

MVVM:How am I supposed to convert a ViewModel into a Model ?

Hello, everyone speaks about wrapping a model by a viewmodel. fine so far. But when I want persist my Model, how do I convert a ViewModel into a Model ? Reading all properties from the ViewModel into a new Model object seems very cumbersome. Any better method? ...

ASP.NET MVC ViewModelBuilder Suggestions

For anything but trival view models, I use a view model builder that handles the responsibility of generating the view model object. Right now, I use constructor injection of the builders into my controllers but this smells a little since the builder is really dependent upon which action method is being executed. I have two ideas in mind...

Easiest way to rename a model using Django/South?

Hi everyone, I've been hunting for an answer to this on South's site, google, and SO, but couldn't find a simple way to do this. I want to rename a Django model using South. Say you have the following: class Foo(models.Model): name = models.CharField() class FooTwo(models.Model): name = models.CharField() foo = models.Fo...

can i call model from other views in rails?

Say I have a model called Book. I have a controller named books and related views for this model. Is it possible if I have another controller work with the model Book? Thanks all. :) ...

Rails Model multiple column uniqueness

I am making a Viewer model with belongs_to :users belongs_to :orders that joins the models Users and Orders with a :has_many :through => :viewers. And the Viewer model has the attributes of user_id and order_id. How would I set it up so that new viewers are only accepted if both user_id and order_id are unique in the same row? I re...

Implementing the tree with reference to the root for each leaf

Hi, i implementing a products catalog, that looks, like this: group 1 subgroup 1 subgroup 2 item 1 item 2 ... item n ... subgroup n group 2 subgroup 1 ... subgroup n group 3 ... group n The Models: class CatalogGroup < ActiveRecord::Base has_many: catalog_items has_many :catalog_item...

Replicating object function across various model files in Ruby on Rails

I am looking to replicate a given object function across various model files As you can see below, the 2 things I need to vary across the model are 1) the "guser" string 2) the self.xxx SIMPLIFIED CODE SAMPLE: def self.get_all statement="SELECT * FROM gusers WHERE" results = results + self.find_by_sql(["#{statement...

Pagination in a Rich Domain Model

I use rich domain model in my app. The basic ideas were taken there. For example I have User and Comment entities. They are defined as following: <?php class Model_User extends Model_Abstract { public function getComments() { /** * @var Model_Mapper_Db_Comment */ $mapper = $this->getMapper(); ...

MVVM/WPF: Using a ObservableCollection<T> as a list in a domain model, is that good/bad ?

I have aggregated models like Customer:Order:Product. As my View is bound to the BillingViewModel which has a Property Customers of type ObservableCollection and ONE customer in this collection has a "list" of orders named ObservableCollection and ONE order in this collection has a "list" of products named ObservableCollection Well ...