[symfony-users] Re: Is there a better way to find a related record other than looping?

2009-05-15 Thread Richtermeister

I would just create a new method:

$entry-findOneMetaDataByType(EntryMeta::Superscript);

In there, for now you can have your loop (no problem with that.. loops
are not all evil).
If at some point you come up with a better solution (for performance
reasons or whatever) you can just change the inner workings of that
method, without breaking the rest of your code.

Everything else would be early optimization I think.

Have a great day,
Daniel



On May 14, 2:22 pm, nick lal...@teamlalala.com wrote:
 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
-~--~~~~--~~--~--~---



[symfony-users] Re: Is there a better way to find a related record other than looping?

2009-05-14 Thread Thomas Rabaix
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
-~--~~~~--~~--~--~---



[symfony-users] Re: Is there a better way to find a related record other than looping?

2009-05-14 Thread David Ashwood
Heh J

 

From: symfony-users@googlegroups.com [mailto:symfony-us...@googlegroups.com] On 
Behalf Of Thomas Rabaix
Sent: 14 May 2009 10:53
To: symfony-users@googlegroups.com
Subject: [symfony-users] Re: Is there a better way to find a related record 
other than looping?

 

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



[symfony-users] Re: Is there a better way to find a related record other than looping?

2009-05-14 Thread David Ashwood

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



[symfony-users] Re: Is there a better way to find a related record other than looping?

2009-05-14 Thread nick

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