model

Can I use a specific model from within a behavior in CakePHP?

I'm trying to write a behavior that will give my models access to a simple workflow engine I've devised. The workflow engine itself works as a CakePHP model, with workflow data stored in the database just as any other model data is stored. Basically what I want to do is have the behavior use the workflow model whenever an action is call...

Rails 2.3.5 model name translation problem in error messages

Hi Rails'ers, I encountered some problem while trying to translate my model's names and attributes in a Rails 2.3.5 app. I have the following model: class BillingPlan < ActiveRecord::Base validates_presence_of :billing_option_id belongs_to :order belongs_to :user belongs_to :billing_option end When validation fails, my m...

Combining Two Models in Rails for a Form

I'm very new with rails and I've been building a CMS application backend. All is going well, but I would like to know if this is possible? Basically I have two models: @page { id, name, number } @extended_page { id, page_id, description, image } The idea is that there are bunch of pages but NOT ALL pages have extended_content. In t...

Is this type of calculation to be put in Model or Controller?

i have Product and SalesOrder model (to simplify, 1 sales_order only for 1 product) Product has_many :sales_orders SalesOrder belongs_to :product pa = Product A #2000 so1 = SalesOrder #1 order product A #1000, date:yesterday so2 = SalesOrder #2 order product A #999, date:yesterday so3 = SalesOrder #3 order product A #1000, date:now...

How to pass parameters to report model in Reporting Services

I'm developing report in RS that show top N customers based on some criteria. It also allows to select number of customers and period of time. Is it possible to do it by using report model? Thing that it seems to be difficult is how to pass parameters determined by user. Another thing that in my oppinion is very disappointing is that i...

#validate does not seem to work correctly with :on => :create/:update

Greetings, I have a custom validation in my exemplary Movie model: class Movie < ActiveRecord::Base validate :it, :on => :create private def it self.errors.add 'foo', 'bar' end end This works on movie creation but also on updating an existing movie. :on => :update will also work for both. Might that be a bug or am I mis...

get request.session from a model method in django

Hay, is it possible to a get a request.session value from a model method in django? MEGA UPDATE Here is my model class GameDiscussion(models.Model): game = models.ForeignKey(Game) message = models.TextField() reply_to = models.ForeignKey('self', related_name='replies', null=True, blank=True) created_on = models.DateTim...

Rails: Serializing objects in a database?

I'm looking for some general guidance on serializing objects in a database. What are serialized objects? What are some best-practice scenarios for serializing objects in a DB? What attributes do you use when creating the column in the DB so you can use a serialized object? How to save a serialized object? And how to access the serializ...

Rails: Creating subfolders in model?

I'm going to have a ton of subclasses, so want to organize them under a subfolder called stream. I added the following line to the environment.rb so that all classes in the subfolder would be loaded: Rails::Initializer.run do |config| ... config.load_paths += Dir["#{RAILS_ROOT}/app/models/*"].find_all { |f| File...

Rails - Accessing model class methods from within ActiveRecord model

I have a simple standalone model that doesn't inherit from ActiveRecord or anything else, called SmsSender. As the name suggests, it delivers text messages to an SMS gateway. I also have an ActiveRecord model called SmsMessage which has an instance method called deliver: def deliver SmsSender.deliver_message(self) self.update_attri...

Can't call method in model table class using Doctrine with Zend Framework

I'm using Doctrine with Zend Framework. For my model, I'm using a base class, the regular class (which extends the base class), and a table class. In my table class, I've created a method which does a query for records with a specific value for one of the fields in my model. When I try and call this method from my controller, I get an e...

Syntax for loading observers (in a model subdirectory) in environment.rb?

I have a lot of model observers, so I want to organize them in a subdirectory under the model folder. model --> observer --> user_observer.rb, activity_observer.rb, etc. Prior to placing in the subdirectory, I was loading the observers like this: Rails::Initializer.run do |config| config.active_record.observers = :user_observer, :...

User settings mechanism for Yii

Hi guys! I need some help with user settings mechanism for my Yii-based application. I've created the following db structure to store user settings: table user with the following fields id | username | email | etc. table settingslist (to store a list of all possible settings with descriptions) with the following fields id | code ...

how to get all 'username' from my model 'MyUser' on google-app-engine ..

my model is : class MyUser(db.Model): username = db.StringProperty() password = db.StringProperty(default=UNUSABLE_PASSWORD) email = db.StringProperty() nickname = db.StringProperty(indexed=False) and my method which want to get all username is : s=[] a=MyUser.all() for i in a: s.append(i.username) and i wa...

Which type of Rails model association should I use in this situation?

I have two models/tables in my Rails application: discussions and comments. Each discussion has_many comments, and each comment belongs_to a discussion. My discussions table also includes a first_comment_id column and last_comment_id column for convenience and speed. I want to be able to call discussion.last_comment for the last comment ...

extending django usermodel

Hi i am trying to create a signup form for my django app. for this i have extended the user model. This is my Forms.py from contact.models import register from django import forms from django.contrib import auth class registerForm(forms.ModelForm): class Meta: model=register fields = ('latitude', 'longitude', 'status') class Met...

Rails ActiveRecord: Select Posts WITHOUT comments

I have a a Comments table and a Posts table, where a Post has many comments and a comment belongs to a post (i.e. it has a post_id in the table). How can I efficiently select the last ten Posts that DO NOT have comments. I can't seem to accomplish this without first selecting all the posts and checking each for a 0 comment count. Thank...

How to validate properties across Models without repeating the validation logic

Hello All, I am building a ASP.NET Mvc app. I have a Data model say User public class user { public int userId {get; private set}; public string FirstName {get; set;} } The validation to be done is that the firstname cannot exceed 50 characters. I have another presentation model in which i have the property FirstName too. I...

Zend Framework-where do calls to my methods go? Controller of Model?

Hi guys, I'm confused about exactly what I should have in my controller and what in my method. Specifically, I have this in the action method: public function upcomingshowsAction() { $gcal = $this->_validateCalendarConnection(); $uncleanedFeedArray = $this->_getCalendarFeed($gcal); $finishedFeedArray = $thi...

How do I call the methods in a model via controller? Zend Framework

Hi guys, I've been searching for tutorials to better understand this, but I'm having no luck. Please forgive the lengthy explination, but I want make sure I explain myself well. First, I'm quite new to the MVC structure, though I have been doing tutorials and learning as best I can. I have been moving over a live site into the Zend Fr...