I'm assuming you also need all of the Entry objects, for some reason
that you did not mention? Because, clearly, if you didn't need all of
the Entry objects, you could just get the EntryMeta objects that you
want with a JOIN statement. But, assuming you need the extra data for
some other reason, you could use a built-in PHP function, like
array_walk(), to look through the array of Entry objects that were
returned from database. I think this still involves a loop, but the
loop is no longer happening in your code, it gets moved to the innards
of array-walk().




On May 13, 11:59 pm, 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
--~--~---------~--~----~------------~-------~--~----~
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