Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

Uploadify overwrites existing hasMany relations – why?


Reply


5 Posts   1040 Views

Avatar
joelg

Community Member, 129 Posts

28 February 2011 at 11:19am

Edited: 28/02/2011 11:21am

Hi Uncle Cheese & co

I've just made a MultipleImageUploadField in a form and I've noticed that Uploadify overwrites the existing image-relations on my has_many relationship. Why?

I've noticed the place to outcomment this in the code (where it sais: "// Null out all the existing relations and reset") and I've done this, but maybe this feature should be an option...

Anyway, what is the reason for this?

Joel

Avatar
UncleCheese

Forum Moderator, 4096 Posts

28 February 2011 at 11:54am

Because the subject of a has_many relationship, by definition, has only one parent. What you're describing is a many_many relationship. I have a patch that allows Uploadify to work with many_many, but I haven't applied it yet.

Actually, you can probably search the forum and find the patch.

Avatar
joelg

Community Member, 129 Posts

28 February 2011 at 12:01pm

Hmm, I don't understand this maybe...

Let me explain. I'm creating an employee object. An employee should have the uppertunity to upload many pictures only attached to the employee object it self. Other employee objects should not have relations to the uploaded pictures. This should be a has_many relationsship for all I know? Or what?

So when the employee opens the multiple upload form and whould like to add more pictures to the existing object it would make sense that the old ones didn't get "deleted" or null'ed.

Please correct if I'm wrong?

Joel

Avatar
UncleCheese

Forum Moderator, 4096 Posts

28 February 2011 at 12:17pm

What you're describing is a has_many. I think you have a problem with your model. What's happening in the block of code you're referring to is that when the page is saved, it destroys all the file relationships and recreates them. The user may have removed files from the list, so every time the page is saved, we rebuild the list.

If you have just added files, then I can't see why you would be having that problem. Can I see your code for the Employee and Photo classes?

Avatar
joelg

Community Member, 129 Posts

28 February 2011 at 12:22pm

Yes. This is my employee class:

<?php
class Employee extends Member {
   
   static $db = array (
      'Nickname' => 'Text',
      'Description' => 'Text',
      //... lot's of stuff here...
      'Status' => 'Enum("Aktiv, Inaktiv")',
      'Note' => 'HTMLText'
   );
   
   static $has_one = array(
   'Picture' => 'Image',
//...more here...
   'Evalutation' => 'EmployeeEvaluation'
);
   
   static $has_many = array(
      'Pictures' => 'BlondImage',
      'EventEvaluations' => 'EventEvaluation',
      'EventRetailEvaluations' => 'EventRetailEvaluation'
   );
   
   static $many_many = array(
      'Skills' => 'Skill',
      'WorkWishes' => 'WorkWish',
   );
   
   static $belongs_many_many = array(
      'Jobs' => 'Job'
   );
//etc...

And this is my BlondImage class:

<?php
class BlondImage extends Image {
      
   static $has_one = array(
   'Employee' => 'Employee'
);
}
?>

The uploadify field is pretty straight too:

new MultipleImageUploadField('Pictures', '', array('buttonText' => 'Vælg billede')