Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Uploadify overwrites existing hasMany relations – why?

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 934 Views
  • joelg
    Avatar
    Community Member
    129 Posts

    Uploadify overwrites existing hasMany relations – why? Link to this post

    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

  • UncleCheese
    Avatar
    4085 Posts

    Re: Uploadify overwrites existing hasMany relations – why? Link to this post

    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.

  • joelg
    Avatar
    Community Member
    129 Posts

    Re: Uploadify overwrites existing hasMany relations – why? Link to this post

    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

  • UncleCheese
    Avatar
    4085 Posts

    Re: Uploadify overwrites existing hasMany relations – why? Link to this post

    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?

  • joelg
    Avatar
    Community Member
    129 Posts

    Re: Uploadify overwrites existing hasMany relations – why? Link to this post

    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')

    934 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.