What is the best code location for defining table relationship methods using Zend Framework models?

I am creating a simple tagging system that allows me to bind a tag to pretty much everything in my application. To facilitate this, I created a table called "Objects" that my Object model refers to.

At the moment, I have three models:

  • Tag
  • (with TagObject defined as dependentTable)
  • Object (with TagObject designated as dependent)
  • TagObject (with tags and object defined in referenceMap)

I've already created a few simple techniques, such as fetchTagById()

, and fetchTagByName()

in my model tag, but now I want to create a method that gets my tags and their corresponding entry in the table objects to create a simple tag cloud.

Structurally, what is the best place to create this method (using findDependentRowset () )?

I somehow feel like it's not a good practice to store this in my Tag model, but storing it in my TagObject model also seems awkward and can be confusing.

Any advice would be greatly appreciated.

Thanks in advance.

+1


source to share


1 answer


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

I would call the model Tags not Tag since Tag is a string in tags and in ZF the model is usually a DataGateway for a table. It's the same with objects.



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

      

In another post, I would never call the class "object" or "objects" because it is too general (objects are a basic language construct). Consider looking for a more descriptive name for it.

+1


source







All Articles