Hello,

If there is only one type per entry then you should use index by
feature. The key of the doctrine collection will be type ... so no
looping is needed

$entry->MetaData[EntryMeta::Superscript] will return the meta data model

On Thu, May 14, 2009 at 5:59 AM, joshuacoady <j...@lovetoknow.com> wrote:

>
> 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
>
> >
>


-- 
Thomas Rabaix
http://rabaix.net

--~--~---------~--~----~------------~-------~--~----~
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