I've been using Objective-C for a while, but I've not been following Apple's guidelines very well. Recently I read Cocoa Design Patterns and the Model Object Implementation Guide, and I'm trying to do some very simple things, but do them very well.
Have I missed any major concepts? Please don't mention self = [super init]; that's been c...
Ive got a view helper in library/my/view/helper/gravatar and so in any view I can call $this->gravatar($email).
But how can I access this function in the models (or controllers)?
Sorry if its already been asked but Im new and the documentation is bloody awful in parts.
Thanks everyone
...
Is it generally better practice (and why) to validate attributes in the model or in the database definition?
For (a trivial) example:
In the user model:
validates_presence_of :name
versus in the migration:
t.string :name, :null => false
On the one hand, including it in the database seems more of a guarantee against any type of b...
A View accepts one Model.
But I need to draw HTML input controls for two models.
An example will illustrate:
I have a screen where I add Employees.
After adding their first name, last name and so on, I need the user to choose a number of Companies the Employees could be in.
The Companies are in one table.
The Employees are in another.
...
Hi,
Is it possible to instantiate a subclassed model from its parent?
class Object1(models.Model):
field1a = models.CharField()
field1b = models.CharField()
feild1c = models.ForeignKey(Object4)
class Object2(Object1):
field3 = models.CharField()
class Object3(Object1):
field3 = models.CharField()
class Object4(models...
Given the following model:
class Project(models.Model):
project_name = models.CharField(max_length=255)
abstract = models.TextField(blank=True, null=True)
full_description = models.TextField(blank=True, null=True)
date_begun = models.DateField(blank=True, null=True)
related_projects = models.ManyToManyField('self', b...
In my tennis application, my 'match' table has two players (obviously). I've used player1_id and player2_id as a way to track the user ids. I haven't included a user_id foreign key though.
There is also a 'user' table where I want to pull player's names from.
Because 'match' has more than one user and users have more than one model, ...
By default, the datetime field from the database is being converted and stripping off the milliseconds:
some_datetime => "2009-11-11T02:19:36Z"
attribute_before_type_cast('some_datetime') => "2009-11-11 02:19:36.145"
If I try to overrride the accessor for this attribute like;
def some_datetime
attribute_before_type_cast('some_datet...
If I have two models that are guaranteed to have a one-to-one correspondence, i.e. if one is created, I will always also need the other, and if one is deleted, I will also want to get rid of the other, what's the best way to tie them together?
I see that the has_one/belongs_to :dependent method takes care of the deletions, but I don't s...
Hi! Is there a way to declare this case so that it works? I hope the code is self-explanatory.
class A(Model):
many_to_one = models.ForeignKey(B)
(...)
class B(A):
(...)
...
Hi,
I am creating small django application which holds some few questions (and answers for them)
What I want to do is to show user random question, but only from those which was not solved by him yet. I wonder how to do this.
For now, I defined user profile model this way:
class UserProfile(models.Model):
rank = models.IntegerFie...
Hi
I'm building an e-commerce website.
I have a Product and Order models.
It's possible that a customer order a product and then the admin change its price
or other fields before the customer actually get it.
A possible solution is to add a 'version' field to the Product model.
When the admin update a product field I'll add a timestamp...
I'm trying to figure out how to use Zend_Db_Table_Abstract correctly. I want to return just the name column from my query. Can you please explain what's wrong with the following code?
class Model_DbTable_Foo extends Zend_Db_Table_Abstract
{
protected $_name = 'foo';
public function getFooById($id) {
$select = $this->select(tr...
Using Zend Framework, I've created a Model to insert a record into a database. My question is, after $this->insert($data) how can I switch the active table so that I can insert a record into another table?
Here's my code so far:
class Model_DbTable_Foo extends Zend_Db_Table_Abstract
{
protected $_name = 'foo';
public function add...
Hi,
I have a model with a version field - autocreate timestamp.
When a model instance is being saved I want to create a new instance with a new timestamp instead of updating the old model instance.
Is it possible?
I thought of overriding the model save() method but I don't know how to create a new instance without creating a infinite ...
Just curious, I spent an embarrassing amount of time trying to get an array of all the records in a nested model. I just want to make sure there is not a better way.
Here is the setup:
I have three models that are nested under each other (Facilities >> Tags >> Inspections), producing code like this for routes.rb:
map.resources :facil...
Hi,
I have an application to count the number of access to an object for each website in a same database.
class SimpleHit(models.Model):
"""
Hit is the hit counter of a given object
"""
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeign...
Hi,
I have 3 models
Recommendation
Job
Qualification
Recommendation model has two fields as work_type and work_id(foreign key for job/qualification based on work_type as "J"/"Q")
I am facing problem in using counter_cache
I have done this in recommendation.rb
belongs_to :job , :counter_cache => true, :foreign_key => "work_id"
b...
I'm not sure of the best structure for a particular situation in Rails. We have several types of workshops. The administration of the workshops is the same regardless of workshop type, so the data for the workshops is in a single model. We collect feedback from participants about the workshops, and the questionnaire is different for each...
I'm working on a CMSy app for which I've implemented a set of models which allow for creation of custom Template instances, made up of a number of Fields and tied to a specific Customer. The end-goal is that one or more templates with a set of custom fields can be defined through the Admin interface and associated to a customer, so that ...