From 4d17cc49170c833f924d0e980feb5485bb3f6b51 Mon Sep 17 00:00:00 2001 From: kaste Date: Tue, 15 Apr 2008 00:54:13 +0000 Subject: [PATCH] Fixes #149 git-svn-id: http://svn.akelos.org/trunk@563 a2fa5c27-f921-0410-a72c-bf682d381be0 --- lib/AkActiveRecord/AkAssociations/AkHasMany.php | 11 +++++------ test/fixtures/app/installers/landlord_installer.php | 4 ++-- test/fixtures/app/installers/picture_installer.php | 4 ++-- test/fixtures/app/installers/property_installer.php | 11 +++++------ 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/AkActiveRecord/AkAssociations/AkHasMany.php b/lib/AkActiveRecord/AkAssociations/AkHasMany.php index 5103d1e..cc9643b 100644 --- a/lib/AkActiveRecord/AkAssociations/AkHasMany.php +++ b/lib/AkActiveRecord/AkAssociations/AkHasMany.php @@ -461,11 +461,10 @@ class AkHasMany extends AkAssociation $options = $this->getOptions($this->association_id); $Associated =& $this->getAssociatedModelInstance(); $owner_id = $this->Owner->quotedId(); - - $table_name = empty($options['include']) ? $Associated->getTableName() : ($set_owner_table_has_included ? '__owner' : $Associated->getTableName()); + $table_name = (!empty($options['include']) || $set_owner_table_has_included) ? '__owner' : $Associated->getTableName(); if(empty($options['finder_sql'])){ - $options['finder_sql'] = ' '.$table_name.'.'.$options['foreign_key'].' = '.(empty($owner_id) ? 'null' : $owner_id).' '; + $options['finder_sql'] = ' '.$table_name.'.'.$options['foreign_key'].' = '.(empty($owner_id) ? 'null' : $owner_id).' '; $options['finder_sql'] .= !empty($options['conditions']) ? ' AND '.$options['conditions'].' ' : ''; } if(empty($options['counter_sql']) && !empty($options['finder_sql'])){ @@ -614,9 +613,6 @@ class AkHasMany extends AkAssociation { $result = false; if(!$this->Owner->isNewRecord()){ - $this->constructSql(); - $has_many_options = $this->getOptions($this->association_id); - $Associated =& $this->getAssociatedModelInstance(); $args = func_get_args(); $num_args = func_num_args(); @@ -629,6 +625,9 @@ class AkHasMany extends AkAssociation $options = array(); } + $this->constructSql(!empty($options['include'])); + $has_many_options = $this->getOptions($this->association_id); + $Associated =& $this->getAssociatedModelInstance(); if (empty($options['conditions'])) { $options['conditions'] = @$has_many_options['finder_sql']; } elseif(!empty($has_many_options['finder_sql']) && is_array($options['conditions']) && !strstr($options['conditions'][0], $has_many_options['finder_sql'])) { diff --git a/test/fixtures/app/installers/landlord_installer.php b/test/fixtures/app/installers/landlord_installer.php index a5725f0..3a85b55 100644 --- a/test/fixtures/app/installers/landlord_installer.php +++ b/test/fixtures/app/installers/landlord_installer.php @@ -5,8 +5,8 @@ class LandlordInstaller extends AkInstaller function install() { $this->createTable('landlords', ' - id integer max=10 auto increment primary, - name string limit=200' + id, + name string(200)' ); } diff --git a/test/fixtures/app/installers/picture_installer.php b/test/fixtures/app/installers/picture_installer.php index f3aa404..b548f9d 100644 --- a/test/fixtures/app/installers/picture_installer.php +++ b/test/fixtures/app/installers/picture_installer.php @@ -5,10 +5,10 @@ class PictureInstaller extends AkInstaller function install() { $this->createTable('pictures', ' - id integer max=10 auto increment primary, + id, property_id, landlord_id, - title string limit=200' + title string(200)' ); } diff --git a/test/fixtures/app/installers/property_installer.php b/test/fixtures/app/installers/property_installer.php index 65d8c29..57f4832 100644 --- a/test/fixtures/app/installers/property_installer.php +++ b/test/fixtures/app/installers/property_installer.php @@ -6,19 +6,18 @@ class PropertyInstaller extends AkInstaller { $this->createTable('properties', ' - id integer max=10 auto increment primary, + id, description string(255), details text, - landlord_id integer, - price integer, - location string limit=200', + price int, + location string(200)', array('timestamp'=>false)); } function uninstall() - { + { $this->dropTable('properties', array('sequence'=>true)); - $this->dropTable('properties_property_types', array('sequence'=>true)); + $this->dropTable('properties_property_types', array('sequence'=>true)); @Ak::file_delete(AK_MODELS_DIR.DS.'property_property_type.php'); } } -- 2.11.4.GIT