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]
  • #121 / May 14, 2012 2:35am

    toopay

    1583 posts

    @Lyken, as i said on previous post, add one more entry, like this :

    self::$relationships = array (
       'part' => ORM::has_many('\\Model\\Site\\Site\\Part => \\Model\\Part\\Part'),
       'site_part' => ORM::has_many('\\Model\\Site\\Site\\Part'),
       'supplier' => ORM::has_many('\\Model\\Supplier\\Supplier'),
       'machine' => ORM::has_many('\\Model\\Machine\\Machine')
      );

    Gas ORM did not perform any JOIN operation, because it could be slower.  Instead, Gas ORM sends a constant number of simple queries (one query for each table type). This implies that volume of transferred data is minimized and the number of queries stays low no matter how many rows are processed. And there are per-request caching options, which make sure no same query executes twice.

  • #122 / Jun 13, 2012 9:31pm

    Lars Germ

    3 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 😊

    This is a very important note! I searched for hours for my problem. Had the same like you!
    Thanks! I think the documentation has a big gap regarding to the foreign key stuff.

    And thanks for the greate ORM! It works pretty well and is really fast. I love it.

  • #123 / Jul 04, 2012 12:01am

    alikwok

    1 posts

    Hello Taufan
    Thank you for your work on Gas. I’m quite new to PHP, CI AND Gas, so hope my questions aren’t too annoying.
    First, a problem acquiring a child object via eager loading:

    $data['inspectors'] = Model\Inspector::order_by('Rank')->all(); //works, $data array has all fields in inspector table.

    BUT when I use:

    $data['inspectors'] = Model\Inspector::with('contact')->all(); //errors

    ———————————————-
    A PHP Error was encountered

    Severity: Warning

    Message: in_array() expects parameter 2 to be array, boolean given

    Filename: classes/core.php

    Line Number: 1575
    ———————————————-

    And if I try to use:

    <?php foreach ($inspectors as $inspector): ?>
    <?php $contact = $inspector->contact; ?>
    <?php echo $contact->Name; ?>                
    <?php endforeach ?>

    $contact->Name causes “Trying to get property of non-object” error.

    Second, (if I can get this eager loading working) is it possible to eager load children’s children, eg:
    Model\Parent::with(‘child’)::with(‘pet’)->all()
    In fact, will Gas allow us to eager load the whole entity tree if we want to?
    Thanks

  • #124 / Jul 04, 2012 6:57am

    toopay

    1583 posts

    @alikwok,

    1. When you work with relationship entity, make sure you read relationship section and follow those rule to set up your models definition. Gas ORM 2 came with dummy models as well, so you can see those models definition as an example. For this issue, most likely it caused by misconfigured relationship.

    2. It is possible.

  • #125 / Jul 09, 2012 10:09am

    Keyur Shah

    21 posts

    i accidentally posted in the gas 1 thread, so reposting here:

    thanks for your hard work, this looks really interesting.

    i am browsing through the hooks and don’t see one for “after get”. so, basically, something that i can use to modify results after they are retrieved, but before sending to the controller. please let me know if you have any plans on adding that.

    thanks!

  • #126 / Jul 11, 2012 6:24am

    Slarv

    2 posts

    Hi,

    I have started using Gas ORM 2.1 and am liking it a lot but have run into a problem with I think may be a bug.

    My development environment is xampp on windows with php 5.3.8.  Everything works fine here. My production environment is centos 6 with 5.3.3. My project doesn’t work here.

    When I move the project to the production environment certain pages don’t load and I get the following error in my logs.

    error_log:
    [Wed Jul 11 19:53:30 2012] [error] [client 192.168.0.10] PHP Fatal error:  Cannot instantiate abstract class Gas\\ORM in /var/www/virtual/codeigniter/application/third_party/gas/classes/orm.php on line 320

    orm.php:

    /**
             * 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);  // this is line 320
            }

    I have narrowed this down to only occurring when I load use gas orm models that have relationships. The problem doesn’t occur on pages with gas orm models that don’t have relationships. If I comment out all the relationships, I no longer get this error in orm.php (but then I do get other expected errors of course)

    I expect an incompatibility with Gas Orm 2.1 and php 5.3.3 but can’t prove it.  I haven’t started to hack at gas orm to see if I can fix it yet.

    Let me know if you need some more info and I will provide it.

    Regards,

    Slarv

     

     

     

  • #127 / Jul 11, 2012 1:29pm

    toopay

    1583 posts

    @Keyur Syah,
    Nice spot, i’ll consider to add that on the next release version.

    @Slarv
    That line is requiring late static bindings feature that only available on PHP 5.3 ++. And you said that in your dev environment everything was fine, so are you sure you runs your app on compatible PHP version? Because most likely this caused by incompatible PHP version.

  • #128 / Jul 11, 2012 7:29pm

    Slarv

    2 posts

    Hi toopay,

    I have just recreated the example application in the GasOrm and I am getting the same behavior.  Just to clarify, I am running into this trouble on php 5.3.3 (according to phpinfo() ).


    As a side note, I will bring your attention to a minor error at http://gasorm-doc.taufanaditya.com/example.html

    Start by building a controller to handle the requests. Create a new file in application/models called blog.php

    Should be ‘Create a new file in application/controllers…’

    Regards,

    Slarv

  • #129 / Jul 12, 2012 12:48pm

    João Barbosa

    3 posts

    @toopay
    I’m getting the same error on line 320.
    I’m using PHP 5.3.3.

    If it helps, I get this error when I tried to add relationships in two models ( ORM::has_one and ORM::belongs_to ).

    Thanks!

  • #130 / Jul 12, 2012 3:00pm

    toopay

    1583 posts

    @Slarv and @Joao Barbosa :

    Try these workaround. On orm.php line 320, change

    final public static function make($record = array())
    {
       return new static($record);  // this is line 320
    }

    into

    final public static function make($record = array())
    {
       $lsb_class = get_called_class();
    
       return new $lsb_class($record); 
    }

     

  • #131 / Jul 13, 2012 1:48pm

    João Barbosa

    3 posts

    @toopay, still the same, just changed the line with error.

    There’s any info I can send you that may be helpful?

  • #132 / Jul 13, 2012 10:41pm

    toopay

    1583 posts

    Well, get_called_class method supposed to work if you run on PHP 5.3.0++. Clearly theres something incompatible in this issue.

    Try contact your hosting support to upgrade their PHP.

  • #133 / Jul 14, 2012 11:53am

    João Barbosa

    3 posts

    I’m trying to use it in localhost yet..
    And using PHP 5.3.3!
    Is there any setting I have to change in my php confg to make it work?

  • #134 / Jul 23, 2012 4:54am

    Tulimiekka

    2 posts

    Hey, nice ORM you have made there. Now only problem I ran into that I can’t seem to be able to solve is tables with reference to itself. I have table named “Category” and there it has ID, CategoryID and Name. This means that category can belong to another as subcategory. My relations are like this:

    $foreign_key = array("\\model\\category" => "CategoryID");
    
    self::$relationships = array(
    "category" => ORM::has_many("\\Model\\Category"),
    "category" => ORM::belongs_to("\\Model\\Category")
    )

    Now if I do something like :

    $CategoryX = Model\Category::find(4);

    It gives normally me an object. Then:

    echo $CategoryX->category()->Name;

    It gives the upper category name. Like if the $CategoryX is BMW, then that one returns “Cars”, which is correct. But what if I want to check vice verca, like the categories under the cars? It should return “BMW, Audi, etc”. But it only gives error of course because it always tries to find some category it belongs to itself and the “Cars” has null as CategoryID.

    So how to find all the childs of some object when relationships are like that? Something I’m doing wrong/missing here? Couldn’t find it in documents.

  • #135 / Jul 23, 2012 12:57pm

    toopay

    1583 posts

    @Tulimiekka,
    You can’t have same entity reference that pointed to different relationship types, as your above example. Try :

    self::$relationships = array(
      'sub_categories' => ORM::has_many('\\Model\\Category'),
      'category' => ORM::belongs_to('\\Model\\Category')
    );
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases