Aron Rotteveel
Aron Rotteveel

Reputation: 83213

What is the best code location to define table relationship methods using Zend Framework models?

I'm creating a simple tag system that allows me to link a tag to almost everything in my application. In order to facilitate this, I created a table called "objects", referenced by my model "Object".

I've got three models setup at the moment:

I already created some simple methods like fetchTagById() and fetchTagByName() in my Tag model, but now I want to create a method that gets my tags and their respective occurences in the objects table, in order to create a simple tag cloud.

Structure-wise, what is the best location to create this method (using findDependentRowset())?

I somehow feel it is not very good practise to store this in my Tag model, but storing it in my TagObject model seems awkward too, and might overcomplicate things.

Any advice would be greatly appreciated.

Thanks in advance.

Upvotes: 1

Views: 304

Answers (1)

Eran Galperin
Eran Galperin

Reputation: 86805

If the method retrieves the tags, then it should be in the tag model. If it retrieves objects, it should be in the object model. Since you are retrieving tags and their occurrences, it should be in the tag model.

I would call the model Tags not Tag, since Tag is a Row in Tags and in the ZF the model is usually a DataGateway to a table. Same with objects.

$tags = new Tags();
$cloud = $tags -> getWithObjectOccurrences();

On another note, I would never name a class "object" or "objects" as it is too generic (objects are a basic language construct). Consider finding a more descriptive name for it.

Upvotes: 1

Related Questions