00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00016 final class OneToManyLinkedLazy extends OneToManyLinkedWorker
00017 {
00021 public function makeFetchQuery()
00022 {
00023 $query =
00024 $this->makeSelectQuery()->
00025 dropFields()->
00026 get($this->container->getChildIdField());
00027
00028 return $this->targetize($query);
00029 }
00030
00035 public function sync(&$insert, &$update = array(), &$delete)
00036 {
00037 Assert::isTrue($update === array());
00038
00039 $db = DBPool::getByDao($this->container->getDao());
00040
00041 $uc = $this->container;
00042 $dao = $uc->getDao();
00043
00044 if ($insert)
00045 $db->queryNull($this->makeMassUpdateQuery($insert));
00046
00047 if ($delete) {
00048
00049 $uc->isUnlinkable()
00050 ?
00051 $db->queryNull($this->makeMassUpdateQuery($delete))
00052 :
00053 $db->queryNull(
00054 OSQL::delete()->from($dao->getTable())->
00055 where(
00056 Expression::in(
00057 $uc->getChildIdField(),
00058 $delete
00059 )
00060 )
00061 );
00062
00063 $dao->uncacheByIds($delete);
00064 }
00065
00066 return $this;
00067 }
00068
00072 private function makeMassUpdateQuery(&$ids)
00073 {
00074 $uc = $this->container;
00075
00076 return
00077 OSQL::update($uc->getDao()->getTable())->
00078 set($uc->getParentIdField(), null)->
00079 where(
00080 Expression::in(
00081 $uc->getChildIdField(),
00082 $ids
00083 )
00084 );
00085 }
00086 }
00087 ?>