使用Propel ORM将多个条目插入Mysql数据库

I am writing a web application using PHP. For the first time I started using Propel ORM. I am reading values from array and sending them to a function which has Propel Insert Queries. The function is like this.

public function someFunction
{
    $nid=10;
    $sample_array = array("first","second");
        foreach($sample_array as $items){
            $this->saveTags($items,$nid);
        } 
}

public function saveTags($tags,$nid)
{
   error_log("SetTag: ".$this->tags->setTag($tags));
   error_log("SetNid: ".$this->tags->setNid($nid));
   error_log("Save: ".$this->tags->save());
}

When I execute the program, the first item "first" saves but immediately overwritten by second item i.e "second". Below are the apache error logs.

 SetTag: Tid: null
Nid: null
Tag: first

 SetNid: Tid: null
Nid: 30
Tag: first

 Save: 1
 SetTag: Tid: 11
Nid: 30
Tag: second

 SetNid: Tid: 11
Nid: 30
Tag: second

 Save: 1

As you can see the first item is replaced by second item! Any solution to prevent this?

Thanks

What is $this->tags ?

I guess, since your are using $this->, that you use the object every time you are going inside the function saveTags().

What you can do is to create a new tags every time, something like:

public function saveTags($tags,$nid)
{
   $tags = new Tags();
   $tags->setTag($tags);
   $tags->setNid($nid);
   $tags->save();

   return $tags;
}

This way, every time you will call saveTags it will create a new tag.