Skip to content

Fatal Error with Polymorphic Attachment Model #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
larry-tx opened this issue Feb 4, 2013 · 3 comments
Closed

Fatal Error with Polymorphic Attachment Model #94

larry-tx opened this issue Feb 4, 2013 · 3 comments

Comments

@larry-tx
Copy link

larry-tx commented Feb 4, 2013

I'm getting an internal error when trying to implement the Upload plugin with the Polymorphic Attachment model. The record gets created in the table (without entries for dir, type, and size), but the file never gets uploaded. I've set the permissions on the files directory to allow full control by Everyone (Windows maching). Specifically, the internal error stack trace is:

Error: An Internal Error Has Occurred.
Stack Trace

[internal function] → UploadBehavior->afterSave(HinvAttachment, boolean, array)
CORE\Cake\Utility\ObjectCollection.php line 130 → call_user_func_array(array, array)
[internal function] → ObjectCollection->trigger(CakeEvent)
CORE\Cake\Event\CakeEventManager.php line 246 → call_user_func(array, CakeEvent)
CORE\Cake\Model\Model.php line 1763 → CakeEventManager->dispatch(CakeEvent)
APP\Controller\HinvAttachmentsController.php line 48 → Model->save(array)
[internal function] → HinvAttachmentsController->add()
CORE\Cake\Controller\Controller.php line 485 → ReflectionMethod->invokeArgs(HinvAttachmentsController, array)
CORE\Cake\Routing\Dispatcher.php line 186 → Controller->invokeAction(CakeRequest)
CORE\Cake\Routing\Dispatcher.php line 161 → Dispatcher->_invoke(HinvAttachmentsController, CakeRequest, CakeResponse)
APP\webroot\index.php line 92 → Dispatcher->dispatch(CakeRequest, CakeResponse)

I can't figure out what's going on. The table looks like this:

CREATE TABLE `hinv_attachments` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `model` varchar(20) NOT NULL DEFAULT 'HinvAttachment',
  `hinv_item_id` int(10) unsigned NOT NULL,
  `name` varchar(255) NOT NULL,
  `attachment` varchar(255) NOT NULL,
  `dir` varchar(255) DEFAULT NULL,
  `type` varchar(255) DEFAULT NULL,
  `size` int(11) DEFAULT NULL,
  `active` tinyint(1) unsigned DEFAULT NULL,
  `user_id` int(10) unsigned DEFAULT NULL,
  `created` datetime DEFAULT NULL,
  `modified` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `IDX_hinv_attachments_name` (`name`),
  KEY `IDX_hinv_attachments_model` (`model`),
  KEY `FK_hinv_attachments_items` (`hinv_item_id`),
  ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;

The model $actsAs looks like this:

        public $actsAs = array(
            'Upload.Upload' => array(
                'attachment',
            ),
            'Acl'           => array(
                'type' => 'controlled'
            ),
        );

I've tried it both with defining the fields (dir, type, and size) and without. The add.ctp form is set to 'type' => 'file'. The file field looks like:

            echo $this->Form->input('attachment', array('type' => 'file'));
            echo $this->Form->input('model', array('type' => 'hidden', 'default' => 'HinvAttachment'));
            echo $this->Form->input('dir', array('type' => 'hidden'));
            echo $this->Form->input('type', array('type' => 'hidden'));
            echo $this->Form->input('size', array('type' => 'hidden'));

What is especially quizzical to me is that the plugin is working just fine with another model. However, in that case, a polymorphic attachment table is not being used. In this case, unfortunately, I need to associate multiple attachments of varying numbers with each record.

Can anyone tell me what I'm doing wrong?

@josegonzalez
Copy link
Member

Please post a zip with an example app exhibiting this error.
On Feb 4, 2013 6:54 PM, "LarryTX" [email protected] wrote:

I'm getting an internal error when trying to implement the Upload plugin
with the Polymorphic Attachment model. The record gets created in the table
(without entries for dir, type, and size), but the file never gets
uploaded. I've set the permissions on the files directory to allow full
control by Everyone (Windows maching). Specifically, the internal error
stack trace is:

Error: An Internal Error Has Occurred.
Stack Trace

[internal function] → UploadBehavior->afterSave(HinvAttachment, boolean, array)
CORE\Cake\Utility\ObjectCollection.php line 130 → call_user_func_array(array, array)
[internal function] → ObjectCollection->trigger(CakeEvent)
CORE\Cake\Event\CakeEventManager.php line 246 → call_user_func(array, CakeEvent)
CORE\Cake\Model\Model.php line 1763 → CakeEventManager->dispatch(CakeEvent)
APP\Controller\HinvAttachmentsController.php line 48 → Model->save(array)
[internal function] → HinvAttachmentsController->add()
CORE\Cake\Controller\Controller.php line 485 → ReflectionMethod->invokeArgs(HinvAttachmentsController, array)
CORE\Cake\Routing\Dispatcher.php line 186 → Controller->invokeAction(CakeRequest)
CORE\Cake\Routing\Dispatcher.php line 161 → Dispatcher->_invoke(HinvAttachmentsController, CakeRequest, CakeResponse)
APP\webroot\index.php line 92 → Dispatcher->dispatch(CakeRequest, CakeResponse)

I can't figure out what's going on. The table looks like this:

CREATE TABLE hinv_attachments (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
model varchar(20) NOT NULL DEFAULT 'HinvAttachment',
hinv_item_id int(10) unsigned NOT NULL,
name varchar(255) NOT NULL,
attachment varchar(255) NOT NULL,
dir varchar(255) DEFAULT NULL,
type varchar(255) DEFAULT NULL,
size int(11) DEFAULT NULL,
active tinyint(1) unsigned DEFAULT NULL,
user_id int(10) unsigned DEFAULT NULL,
created datetime DEFAULT NULL,
modified datetime DEFAULT NULL,
PRIMARY KEY (id),
KEY IDX_hinv_attachments_name (name),
KEY IDX_hinv_attachments_model (model),
KEY FK_hinv_attachments_items (hinv_item_id),
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;

The model $actsAs looks like this:

    public $actsAs = array(
        'Upload.Upload' => array(
            'attachment',
        ),
        'Acl'           => array(
            'type' => 'controlled'
        ),
    );

I've tried it both with defining the fields (dir, type, and size) and
without. The add.ctp form is set to 'type' => 'file'. The file field looks
like:

        echo $this->Form->input('attachment', array('type' => 'file'));
        echo $this->Form->input('model', array('type' => 'hidden', 'default' => 'HinvAttachment'));
        echo $this->Form->input('dir', array('type' => 'hidden'));
        echo $this->Form->input('type', array('type' => 'hidden'));
        echo $this->Form->input('size', array('type' => 'hidden'));

What is especially quizzical to me is that the plugin is working just fine
with another model. However, in that case, a polymorphic attachment table
is not being used. In this case, unfortunately, I need to associate
multiple attachments of varying numbers with each record.

Can anyone tell me what I'm doing wrong?


Reply to this email directly or view it on GitHubhttps://github.com//issues/94.

@larry-tx
Copy link
Author

larry-tx commented Feb 5, 2013

The files are attached. I thought I'd never get the app pared down enough to pass through GitHub's file size limitations!

Larry E. Lutz
2425 Sage Road, Apt. 53
Houston, TX 77056
(713) 850-1358
[email protected]

Date: Mon, 4 Feb 2013 15:55:32 -0800
From: [email protected]
To: [email protected]
CC: [email protected]
Subject: Re: [upload] Fatal Error with Polymorphic Attachment Model (#94)

Please post a zip with an example app exhibiting this error.

On Feb 4, 2013 6:54 PM, "LarryTX" [email protected] wrote:

I'm getting an internal error when trying to implement the Upload plugin

with the Polymorphic Attachment model. The record gets created in the table

(without entries for dir, type, and size), but the file never gets

uploaded. I've set the permissions on the files directory to allow full

control by Everyone (Windows maching). Specifically, the internal error

stack trace is:

Error: An Internal Error Has Occurred.

Stack Trace

[internal function] ¡÷ UploadBehavior->afterSave(HinvAttachment, boolean, array)

CORE\Cake\Utility\ObjectCollection.php line 130 ¡÷ call_user_func_array(array, array)

[internal function] ¡÷ ObjectCollection->trigger(CakeEvent)

CORE\Cake\Event\CakeEventManager.php line 246 ¡÷ call_user_func(array, CakeEvent)

CORE\Cake\Model\Model.php line 1763 ¡÷ CakeEventManager->dispatch(CakeEvent)

APP\Controller\HinvAttachmentsController.php line 48 ¡÷ Model->save(array)

[internal function] ¡÷ HinvAttachmentsController->add()

CORE\Cake\Controller\Controller.php line 485 ¡÷ ReflectionMethod->invokeArgs(HinvAttachmentsController, array)

CORE\Cake\Routing\Dispatcher.php line 186 ¡÷ Controller->invokeAction(CakeRequest)

CORE\Cake\Routing\Dispatcher.php line 161 ¡÷ Dispatcher->_invoke(HinvAttachmentsController, CakeRequest, CakeResponse)

APP\webroot\index.php line 92 ¡÷ Dispatcher->dispatch(CakeRequest, CakeResponse)

I can't figure out what's going on. The table looks like this:

CREATE TABLE hinv_attachments (

id int(10) unsigned NOT NULL AUTO_INCREMENT,

model varchar(20) NOT NULL DEFAULT 'HinvAttachment',

hinv_item_id int(10) unsigned NOT NULL,

name varchar(255) NOT NULL,

attachment varchar(255) NOT NULL,

dir varchar(255) DEFAULT NULL,

type varchar(255) DEFAULT NULL,

size int(11) DEFAULT NULL,

active tinyint(1) unsigned DEFAULT NULL,

user_id int(10) unsigned DEFAULT NULL,

created datetime DEFAULT NULL,

modified datetime DEFAULT NULL,

PRIMARY KEY (id),

KEY IDX_hinv_attachments_name (name),

KEY IDX_hinv_attachments_model (model),

KEY FK_hinv_attachments_items (hinv_item_id),

) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;

The model $actsAs looks like this:

    public $actsAs = array(


        'Upload.Upload' => array(


            'attachment',


        ),


        'Acl'           => array(


            'type' => 'controlled'


        ),


    );

I've tried it both with defining the fields (dir, type, and size) and

without. The add.ctp form is set to 'type' => 'file'. The file field looks

like:

        echo $this->Form->input('attachment', array('type' => 'file'));


        echo $this->Form->input('model', array('type' => 'hidden', 'default' => 'HinvAttachment'));


        echo $this->Form->input('dir', array('type' => 'hidden'));


        echo $this->Form->input('type', array('type' => 'hidden'));


        echo $this->Form->input('size', array('type' => 'hidden'));

What is especially quizzical to me is that the plugin is working just fine

with another model. However, in that case, a polymorphic attachment table

is not being used. In this case, unfortunately, I need to associate

multiple attachments of varying numbers with each record.

Can anyone tell me what I'm doing wrong?

¡X

Reply to this email directly or view it on GitHubhttps://github.com//issues/94.

          ¡X

          Reply to this email directly or view it on GitHub.

@beporter
Copy link

A really common problem is that the Form->create() doesn't have 'type' => 'file' set. That gets me all the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants