Hello!
Firstly, sorry my english is no good.

Url: http://www.symfony-project.org/book/doctrine/1_2/en/06-Working-With-Data
Section: "BlogPost hasMany Tag as Tags"

To ensure duplicate tags are not inserted in to the database, it
suggest:
[php]
class TagTable extends Doctrine_Table
{
  public function findOneByName($name)
  {
    $tag = $this->findOneBy('name', $name);
    if ( ! $tag) {
      $tag = new Tag();
      $tag->name = $name;
    }
    return $tag;
  }
}
[/php]

[php]
class Tag extends BaseTag
{
  public function setName($name)
  {
    $tag = Doctrine::getTable('Tag')->findOneByName($name);
    if ($tag) {
      $this->assignIdentifier($tag->identifier());
    } else {
      $this->_set('name', $name);
    }
  }
}
[/php]

Code suggested by article:
[php]
$blogPost = new BlogPost();
$blogPost->title = 'Test blog post';
$blogPost->body = 'This is the content of the test blog post';
$blogPost->Tags[]->name = 'doctrine';
[/php]

Trace ($blogPost->Tags[]->name = 'doctrine'). Steps:
1) call setName('doctrine')
2) call findOneByName('doctrine')
3) call findOneBy('name','doctrine')
4) 'doctrine' tag not exists in Tag table then create Tag object
inside function "findOneByName"
5) the next step is set name in new tag object ($tag->name =
'doctrine') inside "findOneByName"
6) goto step 1

¿Is correct my test? ¿there is a bucle or not?
Some suggesting!

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