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]
  • #91 / Apr 04, 2012 6:55am

    toopay

    1583 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

    Are you sure you already replace all files respectively? The line you’ve pointed above is contain :

    if ( ! defined('GASSPARKPATH'))

    as shown as this file, and no way it generate above warning. Check your files again.

  • #92 / Apr 04, 2012 7:03am

    toopay

    1583 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

     

    You CAN do that. But make sure each entity’s relationship type, and its property (primary_key and foreign_key) has been set up appropriately.

    Also, by above scenario you’ve used (assume you have set up it correctly), you should access the related entity this way :

    $foo = Model\Foo::with('bar', 'foobar')->find(1);
    $bar = $foo->bar();
    $foobar = $foo->foobar();
  • #93 / Apr 04, 2012 9:08am

    Thibaut L.

    9 posts

    Ok I have made mistake in my relationships 😊

    Edit : I was wrong in my foreign_key, it’s case sensitive \\Model\Foo doesn’t work but \\model\foo yes..

    For Notice message, it’s ok with gitHub version but not with link in 2.1 Documentation.

    Thanks for your help 😊

  • #94 / Apr 04, 2012 11:24am

    Thibaut L.

    9 posts

    Other questions about relationships :

    How can I do this :

    [Foo]
    fID : PrimaryKey
    rowName1
    rowName2
    
    [Bar]
    bID
    rowName1
    rowName2
    
    [FooBar]
    fIDf : Foreign FOO Primary Key
    bIDf : Foreign BAR Primary Key
    Row1
    
    FooBar Tables :
    
    [fIDf] [bIDf] [Row1]
    1       1      data11
    1       2      data12
    2       1      data21

    How can I get data from FooBar Row1 using fIDf and bIDf ?

    I try someting and for the moment, I get data11 and data12, I can’t force using my 2 Primary Keys to get only one row..

    I don’t know if it’s clear :s..i can paste my models here if you want..

     

  • #95 / Apr 05, 2012 8:41am

    toopay

    1583 posts

    @Thibaut L

    For table that identified by some composite key (like FooBar ilustration) try :

    $foobar = Model\Foo\Bar::find(array($foo_id, $bar_id));
  • #96 / Apr 07, 2012 5:17am

    werchter

    3 posts

    Is it correct that in version 2.xx there is no ‘find_where’ anymore?
    If true, that’s really a dealbreaker for me!

    I really liked the fact I could use ActiveRecord conditions to query GAS models in version 1.xx….

  • #97 / Apr 07, 2012 7:51am

    toopay

    1583 posts

    @werchter

    Hey, glad you came into the forum. find_where is removed to avoid redundant API within this ORM. But you still can use something like :

    $user = Model\User::where($condition)->all();

    Feel free to came here if you found some issue on this version 😊

  • #98 / Apr 07, 2012 12:45pm

    werchter

    3 posts

    Thnx!
    Nice to hear that the functionality is still there!

  • #99 / Apr 11, 2012 7:45am

    Jazmo

    13 posts

    What could be problem when i get this error message:

    Fatal error: Cannot instantiate abstract class Gas\ORM in
    /PATH/application/third_party/gas/classes/orm.php on line 317

    /**
      * Serve static calls for ORM instantiation (late binding)
      * 
      * @param  array  set the record
      * @return object
      */
     final public static function make($record = array())
     {
      return new static($record); // LINE 317
     }

    I’m using PHP 5.3
    Any ideas?

  • #100 / Apr 11, 2012 10:15am

    toopay

    1583 posts

    @Jazmo, What line in your application, produce this error? Unless you directly instantiate the abstract class, you’ll never get this error.

  • #101 / Apr 11, 2012 8:55pm

    mecharius

    21 posts

    Hello again toopay, I found a weird situation where some code like the following caused two records to be inserted instead of one:

    $this->model = new Model\User()
    $this->model->username = 'MyUser';
    $this->model->save();
    $this->model = $this->model->last_created();

    I can remove this issue by changing the last line to:

    $this->model->id = $this->db->insert_id();

    Looking at your code from line 2479 of core.php I can’t see why this would be happening!?  Is there an issue with the $this->model=$this->model->last_created() above?  I’ve managed a slightly messy workaround but just wondering if I’m doing something silly.

    This situation has come about because I’m trying to abstract all my repetitive CRUD tasks into a controller… there are callbacks in the child controller which can customise the data being saved, inserted etc and the behaviour after saving.

    EDIT: Although it turns out $this->db->insert_id() is returning 0 even though a record was inserted!?

  • #102 / Apr 12, 2012 2:40am

    toopay

    1583 posts

    @mecharius, as you can see in the source, most of Gas method is rely on CI Query builder. Last created method is rely on insert_id method within Query builder, and if its fail, then this issue more related with CI QB itself. What driver you used (PDO, SQLite, Postgre)? And what version of CI you running?

  • #103 / Apr 13, 2012 1:06pm

    mecharius

    21 posts

    Hi Toopay,  I’m messing around with CI 3.0-dev and mysql. I’ll have a look and see if I can replicate in CI 2.1.  Thanks

  • #104 / Apr 16, 2012 10:24am

    toopay

    1583 posts

    There is new Example application in documentation, created by @mecharius for anyone new to this ORM.

  • #105 / Apr 26, 2012 7:28pm

    khavayero

    14 posts

    Hello Toopay,

    I’m trying update a record from $_POST but I get a error.

    /** Update Record */
       $arrPost = $this->input->post();
       Model\Module\Customer\Models\Phone::make($arrPost)->save(TRUE);

    I have found a solution but I don’t like it

    /** Update Record */
       $arrPost = $this->input->post();
       $objCustomer = Model\Module\Customer\Models\Phone::make($arrPost);
       
       if (isset($objCustomer->empty)){
            $objCustomer->empty = FALSE;
       }
    
       $objCustomer->save(TRUE);

    Can you help me?

    Thanks a lot!

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

ExpressionEngine News!

#eecms, #events, #releases