ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Gas ORM 2

March 16, 2012 11:36pm

Subscribe [39]
  • #76 / Apr 02, 2012 10:54am

    toopay

    1583 posts

    @mecharius, now its getting really weird. From your dump above, the related data container is not set ,which is correct.

    'related' => 
      Gas\Data::__set_state(array(
         'collections' => 
        array (
        ),
      )),

    Now, how core.php line 648 :

    // Check for cascade insert/update
    $entities = $gas->related->get('entities', array());

    could interpret that the related data contain something? Ok lets make sure once more time, alter above dump line into :

    echo '<pre>'.var_export($coursework->related->get('entities', array()), TRUE).'</pre><p>‘;<br />
    // save the model<br />
    if ($coursework->save())  //// **** ERROR HERE
    </pre>
    and alter core.php, just for debug, into :

    // Check for cascade insert/update
    $entities = $gas->related->get('entities', array());
    die('<pre>'.$entities.'</pre><p>‘);
    </pre>

  • #77 / Apr 02, 2012 11:01am

    mecharius

    21 posts

    The first lot gives

    array (
    )
    Array

    If I change the die to var_dump, I get

    array (
    )
    array(0) { }
  • #78 / Apr 02, 2012 11:11am

    toopay

    1583 posts

    @mecharius, ok so entities is an empty array right? So how this line :

    // Check for cascade insert/update
    $entities = $gas->related->get('entities', array());
    // Here you get empty array on $entities, right?
    // Now how come this bellow line evaluated as TRUE?? It should be FALSE.
    
    if ( ! empty($entities))
    {

    You know what i mean? Your script should not came into line 660, since empty array will evaluated FALSE in line 650 at core.php.

  • #79 / Apr 02, 2012 11:33am

    mecharius

    21 posts

    Yeah I agree… so I replaced all the echoes with

    $entities = $gas->related->get('entities', array());
      
      echo (empty($entities) === TRUE ? "EMPTY" : "FULL")."<br>";  
    
      if (empty($entities) === FALSE)
      {
       echo "Checking entities as they are ".(empty($entities) === TRUE ? "EMPTY" : "FULL")."<br>";

    And it gave

    EMPTY
    FULL
    Checking entities as they are FULL
    
    An Error Was Encountered
    Cannot determine the entity models for coursework.0

    ... Huh????

    First of all not sure why one call to save gets two save actions? Perhaps it is related to my first post about this where I noticed that var_dumping $entity gave two array elements? Could it be a strange side effect of the new finder behaviour in 2.1.0?  The full var_dump is too big for here so I’ve uploaded it to my github.

    Looking back through the code I can’t quite work out where these array indices are being set. Any thoughts on how this might come about?  When I add var_dump($entity) at line 660 of core.php I get

    array(2) {
      [0]=>
      object(Model\Coursework)#62 (14) {
        ["primary_key"]=>
        string(2) "id"
    ...

    Should this array have two elements?

  • #80 / Apr 02, 2012 12:00pm

    toopay

    1583 posts

    ... Huh????

    First of all not sure why one call to save gets two save actions? Perhaps it is related to my first post about this where I noticed that var_dumping $entity gave two array elements? Could it be a strange side effect of the new finder behaviour in 2.1.0?

    Well, i dont think so. Maybe you have something else in your code? Controller hooks? or Model callback (after_save etc) that make your application call two actions?

    Other models did not behave like that, right?

    I suggest you do an overhaul over that part.

  • #81 / Apr 02, 2012 12:14pm

    mecharius

    21 posts

    Yeah I’ve been through the code a couple of times and its all pretty basic - I haven’t got any callbacks or hooks at all in the application.  This definitely only happened after the 2.1 update and downgrading to 2.0 fixed the error immediately.  My guess is there is something obscure happening with that model/view/controller and 2.1 but I don’t know what :D

    I am still a bit confused though as to why the $entity object would have 2 records in it even though I’ve used the find() method with an ID? Maybe I’ll look into that a bit more.  I’ll let you know if I find anything.

    Thanks again for your help!

  • #82 / Apr 02, 2012 12:45pm

    mecharius

    21 posts

    I’ve narrowed it down to the following line called a bit later on:

    $sub = Model\Subject::with('coursework')->find($sid);

    If I remove the “with” call and change to

    $sub = Model\Subject::find($sid);

    no error occurs.

  • #83 / Apr 03, 2012 1:51am

    indCI

    11 posts

    Let me know if you still have this issue or you already resolve that.

    I do still have it, but used array_pop() already where I had to. There are other people working on the project where I had the problem so I can’t update to 2.1.0 right now. Like I said I’m quite new to this so I can’t quickly set up any tests for why I had the problem.

  • #84 / Apr 03, 2012 5:36am

    Dan Tdr

    20 posts

    Hello again,

    After the update to 2.1.0 i get a funny error when trying to update:

    here is my code:

    $post_info = $this->input->post();
    
    $notices_settings = Model\Module\Notices\Models\Notices::limit(1)->all(false);
    
    $notices_settings->email_on_new = ($post_info['send_on_new']===true?1:0);
    $notices_settings->email_every = $post_info['send_every'];
    $notices_settings->email_white = $post_info['send_to_manager_w'];
    $notices_settings->email_black = $post_info['send_to_manager_b'];
    
    if ( ! $notices_settings->save(TRUE)):
    echo 'The raw errors were : ';
    print_r($notices_settings->errors);
    $this->session->set_flashdata('error', lang('notices_error'));
    else:
    $this->session->set_flashdata('success', lang('notices_success'));
    endif;

    and i get this error:
    Could not save an entity which define relationship

    my model:

    <?php namespace Model\Module\Notices\Models;
    
    /* This basic model has been auto-generated by the Gas ORM */
    
    use \Gas\Core;
    use \Gas\ORM;
    
    class Notices extends ORM {
     
     public $table = 'notices';
     
     function _init()
     {
      self::$fields = array(
       'email_on_new' => ORM::field('auto[11]'),
       'sms_on_new' => ORM::field('auto[11]'),
       'email_every' => ORM::field('auto[11]'),
       'sms_every' => ORM::field('auto[11]'),
       'email_white' => ORM::field('auto[11]'),
       'sms_white' => ORM::field('auto[11]'),
       'email_black' => ORM::field('auto[11]'),
       'sms_black' => ORM::field('auto[11]'),
      );
    
     }
    }
  • #85 / Apr 03, 2012 9:37am

    toopay

    1583 posts

    @Dan Tdr, your model above did not have either primary_key or foreign_key property.

  • #86 / Apr 03, 2012 9:42am

    Dan Tdr

    20 posts

    @Dan Tdr, your model above did not have either primary_key or foreign_key property.

    is there no way to make it so it does not need a primary_key or foreign_key?
    for example i got this error while extracting some settings from my database, and my settings database table does not have a primary_key, it`s something like:

    setting_name | setting_value

    thanks

  • #87 / Apr 03, 2012 9:56am

    toopay

    1583 posts

    @Dan Tdr, unfortunately, no way you can make it without them. ORM is tend to work with relational entities, thus it need a unique identifier to enforce entity integrity of the table (with a foreign key, for the related tuple, to ensure that referential integrity is maintained between tables).

    I can only give you a suggestion, to add an id collumn with AUTOINCREMENT, to act just as your table index.

  • #88 / Apr 03, 2012 11:40am

    toopay

    1583 posts

    Patch for v.2.1.1

    Changes :
    1. Adding more code coverage around relationships.
    2. Fixed new implemented cascading update method issue(s), which introduced within v 2.1.0 (version 2.1.0 now has beed disabled, due some issues describe throughout this thread).

    How to update :
    If you previously download the zipped files, just re-download and replace the old one. If you installed via Spark, update using this command from your command line :

    $ php tools/spark reinstall -v2.1.1 gas
  • #89 / Apr 04, 2012 5:17am

    Thibaut L.

    9 posts

    Hi, i’ve just update to 2.1.1 and I have following notice :

    Severity: Notice
    
    Message: Use of undefined constant GASSPARKPATH - assumed 'GASSPARKPATH'
    
    Filename: classes/core.php
    
    Line Number: 2197

    I’ve just downloaded zip file, I’m not using Spark

  • #90 / Apr 04, 2012 6:54am

    Thibaut L.

    9 posts

    Hi again,

    I have some issues when I try to use Relationship :

    Foo -> [HAS MANY] -> Bar
    So : 
    Bar-> [BELONGS TO] -> Foo

    It’s ok its works fine.

    But I want :

    Foo -> [HAS MANY] -> Bar
    
    Bar -> [HAS MANY] -> FooBar
    
    So 
    Foo -> [HAS MANY] -> Bar -> [HAS MANY] -> FooBar
        <-  belongs_to <-    <-  belongs_to <-

    I read documentation with Job_user, but I get an error like ‘WHERE foobar.idFoo IN (Array)’
    when I try myFoo->Bar()->FooBar()

    Does anyone tried multi level relationships ?

    Thanks in advance

     

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases