Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6727769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:05:19+00:00 2026-05-26T10:05:19+00:00

I’ve been reading something from Bill Karwin (creator of Zend_DB) about models not being

  • 0

I’ve been reading something from Bill Karwin (creator of Zend_DB) about models not being directly to do with database tables. (I think some devs have their models a direct extension of Zend_tables or so which makes it harder for adding memcached caching of objects, which makes sense.)

So what Bill Karwin was saying is that a Model has tables and isn't a table but I’m still thinking the way I have it is correct as its designed in an object oriented manner.

For instance (just an example):

A Monster has 1:M Mouth. a Mouth has 1:M Tooth. 

So in my database I’d have 5 tables:

Monster: id, name, type
MonsterMouth: id, monster_id, mouth_id
Mouth: id, size
MouthTeeth: id, mouth_id, tooth_id
Tooth: id, size, shape, sharpness

Then the 3 classes:

class Model_Monster { 
    private $id, $name, $type, $mouths = array();
    public function __construct ($id) {
        // Set properties from DB for supplied ID
        // Go through DB and add the mouths based on monster ID
    }

    public function countTeeth () {
        // Loop through each $mouths as $mouth and call $mouth->getTotalTeeth();
    }
} 
class Model_MonsterMouth { 
    private $id, $size, $teeth = array(); 
    public function __construct($id) {
        // Set properties from DB for supplied ID
        // Go through DB and add the types of teeth for this mouth ID
    }

    public function getTotalTeeth () {
        // return sizeof($teeth);
    }

}
class Model_Tooth {
    private $id, $size, $shape, $sharpness;
    public function __construct($id) {
        // Populate details based on ID passed
    }
}

Then I guess methods for counting teeth and stuff…

$monsterId = 1;
$monster = new Monster($monsterId);
// Count total teeth
$totalTeeth = $monster->countTeeth();

So a monster can have many different mouths and 1 mouth can have many different types of teeth.

After writing out this lengthy post I think I’ve got it right and that Bill Karwin is talking about those who have 5 Models rather than 3…

I have 5 Tables but only 3 Models as two tables are there to solve M:M table relationships.

2 of the 3 Models use composition to store many of the other type of object.

If a monster had 10 mouths of between 9-10k of about 10 different types of teeth… would this be a performance issue? I mean would PHP see it like: a,a,a,a,a,b,b or 5*a and 2*b. If having 1-100k of an object and iteratively adding them to a composite item is slow then I guess I should only have one occurance of it with a number property to say how many there are of that type.

If I’ve got it correct then maybe it might help some of the other guys who are having problems with this.

Thanks 😀 Dom

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:05:20+00:00Added an answer on May 26, 2026 at 10:05 am

    Without wishing to put words in Bill the Lizard’s mouth, I think that rather than Many-To-Many-ness, he is more talking about the fact that you should keep separate your abstract concept of a business model from the underlying representation of it.

    It is important for example, not to rely on the fact that the fields in your business model have the same name as the fields in your database/document store/web service, because that makes it very brittle.

    Consider also, if your model wanted to a field like “FullName”, which was a simple concatenation of “FirstName” and “Surname”. You might not really want to store the “FullName” alongside “FirstName” and “Surname” in the database, because it’s duplicate data and more work to keep updated, but if your model is very tightly coupled to the underlying representation, you would either need to a) add “FullName” to your database or b) live without “FullName” in your model.

    By keeping a clean separation, you would be able to have “FullName” in your model and some piece of code that generated it, while just having “FirstName” and “Surname” in the database. Of course, it also makes it much easier to switch out the backend database technology, should you ever need to.

    The key insight from my point of view, is that a Model, more than just the fields it contains, is also the business rules, the validation and potentially the actions that you can perform on it. The table is just the handy place to store the fields necessary to underpin that behaviour.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.