2

What is the best way to store complex models in ZF? In the example below, should each attribute be a separate model entirely, or should the item be a multi dimensional array (as shown below)?

object(Application_Model_Item)#79 (4) {
  ["_id":protected] => int(45)
  ["_name":protected] => string(5) "Bolts"
  ["_description":protected] => NULL
  ["_attributes":protected] => array(2) {
    [0] => array(2) {
      ["id"] => string(1) "3"
      ["name"] => string(4) "Size"
    }
    [1] => array(2) {
      ["id"] => string(1) "4"
      ["name"] => string(6) "Length"
    }
  }

Thanks in advance.

1
  • Do you have any specific ORM requirements? Would a suggestion detailing Doctrine ORM be okay? Commented Aug 11, 2010 at 12:20

2 Answers 2

1

It all depends on your use case:

Indexing by ID or Position:

  • If you would like speed when accessing a particular attribute, then index the attributes by their IDs instead of their index position.
  • If you would like to keep an order, then order them by index position and a position offset amount.

Independent Table Vs Local Array:

  • If the attributes are duplicated in multiple items, then have them as their own table, and reference the attributes to that table.
  • If the attributes are not refenced and are unique to each item, then using them as serialise-able arrays (for storage) is adequate than needing them to be their own table.
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the reply. I really should take a look at doctrine it's just I'm too lazy to learn a new language. I've also heard doctrine can become quite resource intensive so I was planning on coding the mappers myself (in php).
No worries, hope I helped :-) Doctrine is actually fairly simple to learn, I moved to it after my own ORM was getting a bit too legacy. It is quite resource intensive and difficult to debug at times, but I don't regret the move as the downfalls are entirely reasonable as well.
0

In the case of _attributes i would use array of objects. So it attributes would be an array of new model Attribute()

I make a class for every business model entity

["_attributes":protected] => array(2) {
    [0] => Object(Model_Attribute) {}
    [1] => Object(Model_Attribute) {}
}

class Model_Attribute {
  protected $id;
  public function getId();
  public function setId($id);
  .
  .
  .
}

I suggest you look at Doctrine ORM 2.0 since it can support the design from the above. Look at this page, it may give you a clue: http://www.doctrine-project.org/projects/orm/2.0/docs/reference/association-mapping/en

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.