0

I am attempting to create a new model that joins to tables and presents them using CRUD, following this example.

What am I missing? Will this not work with a) filestore? b) CRUD? or c)?

There is a customer contact table:

class Model_Contact extends Model_Table {
   public $table='customercontact';
       function init(){
          parent::init();

          $this->addField('ContactDate')->type('date')->caption('Contact Date');
          $this->addField('ContactNotes')->caption('Notes');

        }
}

And there is a contactattachments table:

class Model_ContactAttachments extends Model_Table {
       public $table='contactattachments';
           function init(){
              parent::init();

              $this->addField('ContactID');
              $this->add('filestore/Field_File','FilestoreID')->caption('Upload File');
           }
    }   

And here is the combined table, following the example as I understand it:

class Model_Contact extends Model_Table {
   public $table='customercontact';
       function init(){
          parent::init();

          $this->addField('ContactDate')->type('date')->caption('Contact Date');
          $this->addField('ContactNotes')->caption('Notes');

          $detail = $this->join('ContactAttachments.ContactID');
          $detail->add('filestore/Field_File','FilestoreID')->caption('Upload File');

       }
}

Results in this error:

Application Error: Method is not defined for this object

Exception_Logic, code: 0

Additional information:

class: SQL_Relation
method: addExpression
arguments:
0: ContactAttachments.FilestoreID_text
C:\Program Files (x86)\EasyPHP-DevServer-13.1VC11\data\localweb\atk4\lib\AbstractObject.php:846

Stack trace:
File        Object Name Stack Trace
C:\Program Files (x86)\EasyPHP-DevServer-13.1VC11\data\localweb\atk4\lib/BaseException.php  :63     Exception_Logic Exception_Logic->collectBasicData(Null)
C:\Program Files (x86)\EasyPHP-DevServer-13.1VC11\data\localweb\atk4\lib/AbstractObject.php :545    Exception_Logic Exception_Logic->__construct("Method is not defined for this object", Null)
C:\Program Files (x86)\EasyPHP-DevServer-13.1VC11\data\localweb\atk4\lib/AbstractObject.php :846    asol_index_tabs_view_htmlelement_4_crud_model_contact__C    SQL_Relation->exception("Method is not defined for this object", "Logic")
C:\Program Files (x86)\EasyPHP-DevServer-13.1VC11\data\localweb\atk4\lib\Field/Reference.php    :30     asol_index_tabs_view_htmlelement_4_crud_model_contact__C    SQL_Relation->__call("addExpression", Array(1))
C:\Program Files (x86)\EasyPHP-DevServer-13.1VC11\data\localweb\atk4\lib\Field/Reference.php    :30     asol_index_tabs_view_htmlelement_4_crud_model_contact__C    SQL_Relation->addExpression("ContactAttachments.FilestoreID_text")
C:\Program Files (x86)\EasyPHP-DevServer-13.1VC11\data\localweb\atk4-addons\filestore\lib\Field/File.php    :7  ead9409b__act__C_ContactAttachments.FilestoreID filestore\Field_File->setModel("filestore/File", "url")
C:\Program Files (x86)\EasyPHP-DevServer-13.1VC11\data\localweb\atk4\lib/AbstractObject.php :306    ead9409b__act__C_ContactAttachments.FilestoreID filestore\Field_File->init()
C:\Program Files (x86)\EasyPHP-DevServer-13.1VC11\data\localweb\lib\Model/Contact.php   :19     asol_index_tabs_view_htmlelement_4_crud_model_contact__C    SQL_Relation->add("filestore/Field_File", "ContactAttachments.FilestoreID")
C:\Program Files (x86)\EasyPHP-DevServer-13.1VC11\data\localweb\atk4\lib/AbstractObject.php :306    asol_index_tabs_view_htmlelement_4_crud_model_contact   Model_Contact->init()
C:\Program Files (x86)\EasyPHP-DevServer-13.1VC11\data\localweb\atk4\lib/AbstractObject.php :400    asol_index_tabs_view_htmlelement_4_crud CRUD->add("Model_Contact")
C:\Program Files (x86)\EasyPHP-DevServer-13.1VC11\data\localweb\atk4\lib/AbstractView.php   :92     asol_index_tabs_view_htmlelement_4_crud CRUD->setModel("Contact")
C:\Program Files (x86)\EasyPHP-DevServer-13.1VC11\data\localweb\atk4\lib\View/CRUD.php  :220    asol_index_tabs_view_htmlelement_4_crud CRUD->setModel("Contact")
C:\Program Files (x86)\EasyPHP-DevServer-13.1VC11\data\localweb\page/index.php  :29     asol_index_tabs_view_htmlelement_4_crud CRUD->setModel("Contact")
C:\Program Files (x86)\EasyPHP-DevServer-13.1VC11\data\localweb\atk4\lib/AbstractObject.php :306    asol_index  page_index->init()
C:\Program Files (x86)\EasyPHP-DevServer-13.1VC11\data\localweb\atk4\lib/ApiFrontend.php    :130    asol    Admin->add("page_index", "index", "Content")
C:\Program Files (x86)\EasyPHP-DevServer-13.1VC11\data\localweb\atk4\lib/ApiWeb.php :428    asol    Admin->layout_Content()
C:\Program Files (x86)\EasyPHP-DevServer-13.1VC11\data\localweb\atk4\lib/ApiFrontend.php    :39     asol    Admin->addLayout("Content")
C:\Program Files (x86)\EasyPHP-DevServer-13.1VC11\data\localweb\atk4\lib/ApiWeb.php :275    asol    Admin->initLayout()
C:\Program Files (x86)\EasyPHP-DevServer-13.1VC11\data\localweb/index.php   :15     asol    Admin->main()
Note: To hide this information from your users, add $config['logger']['web_output']=false to your config.php file. Refer to documentation on 'Logger' for alternative logging options
Community
  • 1
  • 1
Mark
  • 27
  • 5

1 Answers1

0

In join you have to use table name, not a class name

function join($foreign_table, $master_field=null, $join_kind=null, $_foreign_alias=null,$relation=null){
Kostiantyn
  • 1,792
  • 2
  • 16
  • 21
  • You are correct re: the join... thank you. This fixed the join: $detail = $this->join('contactattachments.ContactID', 'id'); However, I'm still left with figuring out the original issue (Method not defined...) when using 'add' in an attempt to get filestore to work on the joined table. It works fine on the primary one - thing is, I want to be able to attach multiple files to a contact record. – Mark Nov 16 '13 at 01:29
  • 1
    Use addField() method instead of add() cause you are trying add class but you need to add field. – Kostiantyn Nov 17 '13 at 06:44
  • When I use addField, I just get a plain field and not the button to add a file attachment - as when I use filestore elsewhere. Thx. – Mark Nov 17 '13 at 18:33
  • Oh. You have not mentioned that you want to add button to each row (if I understant correctly). I can be wrong but I think you can try to add a column to the crud like so$crud->addColumn('button','your_field_name','Add file');. – Kostiantyn Nov 18 '13 at 21:09
  • It looks that it's not possible to do this way (at least for now). The thing is that when you add(filestore), then addExpression is created too (in filestore add-on). And addExpression can't be used in SQL_Relation class. You can add(filestore) only to Model class. – DarkSide Nov 19 '13 at 10:37
  • Ok, well thank you. Since we've exhausted the initial approach, any recommendations for an alternative approach? Goal: capture a contact event (call, e-mail, etc) and allow multiple files to be attached and easily reviewed later. Suppose a popup might work... :) – Mark Nov 20 '13 at 05:26