Depending on how the data is organised you can try:

        $entry->MetaData[EntryMeta::Superscript]['value'] or
$entry->MetaData[EntryMeta::Superscript]->value


-----Original Message-----
From: symfony-users@googlegroups.com [mailto:symfony-us...@googlegroups.com]
On Behalf Of joshuacoady
Sent: 14 May 2009 05:59
To: symfony users
Subject: [symfony-users] Is there a better way to find a related record
other than looping?


The schema for this is below, but say I'm working with the Entry
object and the query that loads the Entry object also loads the
related EntryMeta at the same time. Now, I want to find the Entry's
MetaData record that has a particular value for type. Is there a
better way to do this than to loop through all of the Entry's
MetaData?

      foreach($entry->MetaData as $meta)
      {
         if($meta->type == EntryMeta::Superscript)
         {
            $superscript = $meta->value;
            break;
         }
      }

Is there a way to do something more like the following?

$superscript = $entry->MetaData->findOneByType(EntryMeta::Superscript)-
>value;

And neither of these should query the DB since I've already loaded all
the Entry's MetaData when I originally queried the DB for the Entry.
Is there some way to do this that I'm missing?

Thanks!


Entry:
  columns:
    id:
      type: integer
      primary: true
      autoincrement: true
      notnull: true
    slug:
      type: string(255)
      notnull: true
    headword:
      type: string(255)
      notnull: true
  options:
    type: INNODB
    collate: utf8_unicode_ci
    charset: utf8
  indexes:
    slug:
      fields: [slug]

EntryMeta:
  columns:
    id:
      type: integer
      primary: true
      autoincrement: true
      notnull: true
    entry_id:
      type: integer
      notnull: true
    type:
      type: integer
      notnull: true
    value:
      type: string(2000)
      notnull: true
  indexes:
    uk_type:
      fields: [entry_id, type]
      type: unique
  relations:
    Entry:
      local: entry_id
      foreign: id
      foreignAlias: MetaData



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to