Welcome Guest, Not a member yet? Register   Sign In
Gas ORM
#81

[eluser]toopay[/eluser]
@lnguyen, what exactly you need.

@jameshang, thats how ActiveRecord ORM works. If you need more adjustment, consider to write Gas ORM extension.
#82

[eluser]lnguyen[/eluser]
@toopay: may be count_all_result() function is not working. So you can check it or guide me how can i count all record with my conditions.

-----------------------
Now i added code in Gas.php file and it working good:
Code:
public function count()
{
    return count($this->select($this->primary_key)->all());
}
#83

[eluser]rei[/eluser]
Hi, I'm doing something like this:

Code:
$all_users = Model\User::with('blog')->all();

                foreach ($all_users as $some_user)
                {
                        echo 'User ' .$some_user->username.' and he seems have several kids:';

                        foreach ($some_user->blog() as $blog)
                        {
                            echo '<br>';
                            echo '<br>';
                            echo '<br>';
                            echo '<br>';
                            echo $blog->title ;
                            echo '<br>';
                            echo '<br>';
                            echo '<br>';
                            echo '<br>';
                        }



But why the output is:
Code:
User kevin and he seems have several kids:User francie and he seems have several kids:


francies first post


francies second post


francie 3rd

It is just showing francie's post, but not showing kevin's post? Is this a bug?


I enabled CI profiler and the created query is this:

Code:
0.0004    SELECT *
FROM (`user`)
0.0004    SELECT * FROM `blog` WHERE `blog`.`user_id` IN (2)
#84

[eluser]rei[/eluser]
I also tried this one and its giving me the results I wanted:

Code:
$all_users = Model\User::all();

                foreach ($all_users as $some_user)
                {
                        echo 'User ' .$some_user->username.' and he seems have several kids:';

                        foreach ($some_user->blog() as $blog)
                        {
                            echo '<br>';
                            echo '<br>';
                            echo '<br>';
                            echo '<br>';
                            echo $blog->title ;
                            echo '<br>';
                            echo '<br>';
                            echo '<br>';
                            echo '<br>';
                        }

                }

But the problem is its making this queries:

Code:
0.0004    SELECT *
FROM (`user`)
0.0004    SELECT * FROM `blog` WHERE `blog`.`user_id` IN (2)
0.0003    SELECT * FROM `blog` WHERE `blog`.`user_id` IN (1)

It always makes a new query for fetching the blog posts of EACH user. Which is not good for performance, so I really wanted to use eager loading like this one:

Code:
$all_users = Model\User::with('blog')->all();

I hope you can resolve the problem. Thanks Smile


#85

[eluser]redcloud80[/eluser]
Hi! I'm trying to use Gas ORM but I'm stuck with a many-to-many relationship.

I've two tables A, B linked by a third C table


Code:
A fields: [id, name]
B fields: [id, name]
C fileds: [id, a_id, b_id, value]

on C table, a_id and b_id are FK to related tables.

What I'm trying to do is to get for each A item, his name, the name of related B items plus the value from C table.

E.g.
Code:
John, Red, 10
John, Blue, 12
Mike, Red, 11

This is how I've defined relationships

In A model:
Code:
self::$relationships = array(
    'a'  => ORM::has_many('\\Model\\B\\A => \\Model\\A')
);

In B model:
Code:
self::$relationships = array(
    'b'  => ORM::has_many('\\Model\\B\\A => \\Model\\B')
);

In C model:
Code:
self::$relationships = array(
    'b' => ORM::belongs_to('\\Model\\B'),
    'a' => ORM::belongs_to('\\Model\\A'),
);

Then I get some data using this code:
Code:
$data['items'] = Model\A::with('b')->all();

So I can use it into view
Code:
foreach ($items as $a) {
    foreach ($a->b() as $b) {
        // Here I need to show the value field from C table
    }
}

And now the question, does this query $data['items'] = Model\A::with('b')->all(); retrieves C table data too?
#86

[eluser]toopay[/eluser]
No. But you could specify has_many C relationship in your A entity. Btw, this is thread for older version, go to this thread if you have further question on Gas ORM 2.
#87

[eluser]Odie[/eluser]
Hi,

Just like to know if its possible to use memcache for the caching Gas is doing?
#88

[eluser]lnguyen[/eluser]
I found a bug.
If you use join with limit conditions. Limit is return 0.
Example:
Code:
//some code...
$results = Gas::factory('sections')->select('sections.*, buildings.name as bname, directions.name as dname')
                 ->order_by($sortname, $sortorder)
   ->left_join_buildings('buildings.id = sections.building_id')
   ->left_join_directions('directions.id = sections.direction_id')
   ->limit($limit, $offset)
   ->all();
echo Gas::factory('sections')->last_sql();

//result
SELECT ... LIMIT 0

I'm fixed. In file Gas.php line 5097.
Code:
//add code: and $type != 'limit' after $node
if ( ! in_array($type, $preserve) and $type == $node and $type != 'limit')
{
    //...
}
Sorry for my EL.
#89

[eluser]toopay[/eluser]
@lnguyen, thanks.
#90

[eluser]Kimse[/eluser]
http://gasorm-doc.taufanaditya.com/valid...amp-fields

Why does GasORM use "12-hour format of an hour with leading zeros" is this a mistake or by purpose?





Theme © iAndrew 2016 - Forum software by © MyBB