[symfony-users] Circular references in fixtures (patch for sfPropelData.class.php)
I believe there is currently no support for circular references in data fixtures. I have created a patch for sfPropel15Plugin that allows this, and I think it can be easily adapted for Doctrine or Propel 1.4. My solution allows you to update an already defined and saved object, and it provides an onDelete -> setNull syntax to "unravel" the circular reference when removing the data. I have done some research for existing solutions, but I only found unanswered questions (eg. [ http://groups.google.com/group/symfony-users/browse_thread/thread/f1bc6a2e811c545d/24e673ca8b14296c ], [ http://forum.symfony-project.org/index.php/m/95747/ ]), so I think there is a need for this. Current limitations: - The update of an object must happen in a different file, since sfYaml overwrites the first group in the file with the second, but not across files. - loadMany2Many has not been changed (yet), so I don't know whether that syntax also works. Example usage: schema.yml: Parent: parent_id name preferred_child_id (default null) Child: child_id name parent_id The preferred_child_id is the circular reference: we cannot create it before one Child exists, but we cannot create a Child without a Parent. fixtures/parents.yml: Parent: John: name: John fixtures/children.yml: Child: Alfred: name: Alfred parent_id: John Beatrice: name: Beatrice parent_id: John Parent: John: preferred_child_id: Alfred _onDelete: setNull: preferred_child_id All comments are welcome. Greetings, Jan Fabry Index: plugins/sfPropel15Plugin/lib/addon/sfPropelData.class.php === --- plugins/sfPropel15Plugin/lib/addon/sfPropelData.class.php (revision 29402) +++ plugins/sfPropel15Plugin/lib/addon/sfPropelData.class.php (working copy) @@ -132,9 +132,20 @@ { throw new InvalidArgumentException(sprintf('Unknown class "%s".', $class)); } + +// Skip entries starting with an underscore +if (strncmp($key, '_', 1) === 0) { + continue; +} + +$referenceKey = Propel::importClass(constant(constant($class.'::PEER').'::CLASS_DEFAULT')).'_'. $key; + +if (array_key_exists($referenceKey, $this- >object_references)) { + $obj = $this->object_references[$referenceKey]; +} else { + $obj = new $class(); +} -$obj = new $class(); - if (!$obj instanceof BaseObject) { throw new RuntimeException(sprintf('The class "%s" is not a Propel class. This probably means there is already a class named "%s" somewhere in symfony or in your project.', $class, $class)); @@ -197,7 +208,7 @@ // save the object for future reference if (method_exists($obj, 'getPrimaryKey')) { - $this- >object_references[Propel::importClass(constant(constant($class.'::PEER').'::CLASS_DEFAULT')).'_'. $key] = $obj; + $this->object_references[$referenceKey] = $obj; } } } @@ -288,10 +299,28 @@ throw new InvalidArgumentException(sprintf('Unknown class "%sPeer".', $class)); } -$this->log(sprintf('deleting data from %s', $class)); -call_user_func(array(constant($class.'::PEER'), 'doDeleteAll'), $this->con); + +if (array_key_exists('_onDelete', $data[$class])) { + $this->log(sprintf('executing onDelete sequence of %s', $class)); + if (array_key_exists('setNull', $data[$class] ['_onDelete'])) { +$nullableFields = $data[$class]['_onDelete']['setNull']; +if (!is_array($nullableFields)) { + $nullableFields = array($nullableFields); +} +$updateCriteria = new Criteria(); +$tableName = constant(constant($class.'::PEER').'::TABLE_NAME'); +foreach ($nullableFields as $field) { + // Camelize? + $updateCriteria->add($tableName . '.' . $field, null); +} +call_user_func(array(constant($class.'::PEER'), 'doUpdate'), $updateCriteria, $this->con); + } +} else { + $this->log(sprintf('deleting data from %s', $class)); + call_user_func(array(constant($class.'::PEER'), 'doDeleteAll'), $this->con); + $this->deletedClasses[] = $class; +} -$this->deletedClasses[] = $class; } } } -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com 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: DBFinderPlugin future
You can find my patch for the unit tests here: [ http://pastebin.com/f18abd80b ]. This passes all tests on MySQL. It probably can be improved, but hopefully it is enough to motivate someone to start on the Doctrine part! Greetings, Jan Fabry On Dec 6, 3:53 pm, Daniel Lohse wrote: > That is very good news! I'll see what I can do about the Doctrine test part. > > Maybe when I'm done we could then open a ticket with both patches attached? > That would improve the chances of the patch being accepted soon > andDbFinderupdated for symfony 1.4. > > One potential problem is that the admin generator feature relies on symfony > 1.0 code and therefore would have to be completely rewritten or entirely > removed for the time being. But that is for Francois to decide. :) > > Cheers, Daniel > > On 2009-12-06, at 6/December, 3:26 PM, Jan Fabry wrote: > > > > > On Dec 3, 11:50 am, Daniel Lohse wrote: > >> Alright, there you go, it's really only 2 lines changed at this time. :) > > >> Report back if you're hitting any roadblocks but my app uses > >> hydration/joins quite extensively and it works just like before (minus > >> that little bug I mentioned which I have to hunt down today, will report > >> back if it's something to do withDbFinder). > > > I have updated the unit tests for the Propel part, and they all pass > > with this patch. I did need to rewrite some tests (to adapt them to > > syntax changes in the output of Propel 1.4, or to make them completely > > isolated from other tests), but I will wrap up those changes in > > another post to this list or in a Trac ticket. > > > I did not yet go through the Doctrine or common tests, since that will > > probably require more work in theDbFindercode - maybe someone with > > more knowledge of the Doctrine internals could start with that? > > > Greetings, > > > Jan Fabry > > > -- > > > You received this message because you are subscribed to the Google Groups > > "symfony users" group. > > To post to this group, send email to symfony-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > symfony-users+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/symfony-users?hl=en. -- You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-us...@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: DBFinderPlugin future
On Dec 3, 11:50 am, Daniel Lohse wrote: > Alright, there you go, it's really only 2 lines changed at this time. :) > > Report back if you're hitting any roadblocks but my app uses hydration/joins > quite extensively and it works just like before (minus that little bug I > mentioned which I have to hunt down today, will report back if it's something > to do with DbFinder). I have updated the unit tests for the Propel part, and they all pass with this patch. I did need to rewrite some tests (to adapt them to syntax changes in the output of Propel 1.4, or to make them completely isolated from other tests), but I will wrap up those changes in another post to this list or in a Trac ticket. I did not yet go through the Doctrine or common tests, since that will probably require more work in the DbFinder code - maybe someone with more knowledge of the Doctrine internals could start with that? Greetings, Jan Fabry -- You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-us...@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: DBFinderPlugin future
On Nov 19, 12:20 pm, Gareth McCumskey wrote: > You can stick with Propel can't you? Doctrine is only the default plugin and > can be changed to use Propel instead. Yes, the standard functionality of DbFinder might work (the simpler querying), but I was thinking about the admin generator stuff. However, it seems that does not even work too well under Symfony 1.2, so it might be better to just go with 1.3, and do the required admin changes manually, or with other plugins. Still, it would be nice to have a current, working and widely used DbFinderPlugin, certainly with the transition to Doctrine as the default ORM. Is anyone still motivated to look at the open bugs, or is extra help required to get them fixed? Greetings, Jan Fabry > > On Thu, Nov 19, 2009 at 11:18 AM, Jan Fabry wrote: > > Hello, > > > Is anyone working on updating DbFinderPlugin for Symfony 1.3/1.4, and > > the included versions of the ORM frameworks? I don't know whether > > François will spend more time on it, and I don't see any other > > activity. > > > I would like to use it for a new project, but I guess the best way to > > do this is start with Symfony 1.2 now, wait for the plugin, and > > upgrade to 1.3/1.4 when it is ready? > > > If it is clear that no-one is planning to spend time on it, I might > > try it. I come from a Propel background, but my knowledge of the > > internals of Doctrine and Symfony needs work. > > > Greetings, > > > Jan Fabry > > > -- > > > You received this message because you are subscribed to the Google Groups > > "symfony users" group. > > To post to this group, send email to symfony-us...@googlegroups.com. > > For more options, visit this group at > >http://groups.google.com/group/symfony-users?hl=. > > -- > Gareth McCumskeyhttp://garethmccumskey.blogspot.com > twitter: @garethmcc -- You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-us...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/symfony-users?hl=.
[symfony-users] DBFinderPlugin future
Hello, Is anyone working on updating DbFinderPlugin for Symfony 1.3/1.4, and the included versions of the ORM frameworks? I don't know whether François will spend more time on it, and I don't see any other activity. I would like to use it for a new project, but I guess the best way to do this is start with Symfony 1.2 now, wait for the plugin, and upgrade to 1.3/1.4 when it is ready? If it is clear that no-one is planning to spend time on it, I might try it. I come from a Propel background, but my knowledge of the internals of Doctrine and Symfony needs work. Greetings, Jan Fabry -- You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-us...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/symfony-users?hl=.
[symfony-users] Re: Doctrine_Record_UnknownPropertyException
On Nov 18, 12:23 pm, Jan Fabry wrote: > On Nov 4, 6:56 am, theprodigy wrote: > > > I'm receiving an error of type: > > Doctrine_Record_UnknownPropertyException (Unknown method > > Company::getAddress2) > > I am seeing the same problem with a column named 'phone_1'. Maybe it > is related to the digit at the end of the column name? If that is the > case, this is a problem with Doctrine, not Symfony. Ah, the problem is the extra underscore before the digit. Both "some_column_1" and "some_column1" are converted to "someColumn1". When trying to do the reverse operation (in sfDoctrineRecord::__call, which uses sfInflector::underscore), the second form ("some_column1") is returned. So, don't use underscores before digits! I don't know if there is a way to fix this? When using the Propel ORM, both name styles are preserved in the peer-classes, so I think the problem would not surface there? Is this documented somewhere? Greetings, Jan Fabry -- You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-us...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/symfony-users?hl=.
[symfony-users] Re: Doctrine_Record_UnknownPropertyException
On Nov 4, 6:56 am, theprodigy wrote: > I'm receiving an error of type: > Doctrine_Record_UnknownPropertyException (Unknown method > Company::getAddress2) I am seeing the same problem with a column named 'phone_1'. Maybe it is related to the digit at the end of the column name? If that is the case, this is a problem with Doctrine, not Symfony. I am trying to find where the name is converted to CamelCase, that is also a nice way to learn to know the inner workings of Doctrine :-) Jan -- You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-us...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/symfony-users?hl=.