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

[eluser]toopay[/eluser]
Its a mistake. Already spotted, fixed and merged into recent codebase three months ago
#92

[eluser]darkylmnx[/eluser]
Hi, i tried to do an auto-create models from database, it does the "SHOW TABLES FROM `database` " but it doesn't generate the models

i set the migration lib config to TRUE and the auto_create_models to TRUE, but no models generated... any idea ?

----

I found the problem. Now new problem, it show me
Code:
Message: mkdir() [function.mkdir]: No such file or directory

there are lot of relations in my table if that helps to understand.
#93

[eluser]Thibaut L.[/eluser]
Hi,

I wanted to know how I can use Gas ORM with two databases ?

In my database.php I've set up my "default" DB connection, and a "secondary".

But how in my ORM model I can set which connection I use ?


Thanks in advance
#94

[eluser]toopay[/eluser]
@Thibaut L. Your model won't care and they are not aware about the connection you used at a time.

You need to tell \Gas\Core class to change from one connection into another. Gas model always use static connection from the core class.

Code:
Gas\Core::connect('default');

var_dump(Model\User::find(1)); // will output user from default connection

Gas\Core::connect('secondary');

var_dump(Model\User::find(1)); // will output user from secondary connection

As described here
#95

[eluser]Thibaut L.[/eluser]
Thanks it's working !

Another question, I try to use validation in my model like the documentation, but I am able to save my user in the database without setting username whereas I've set 'required'.


Code:
<?php

namespace Model\Members;

use \Gas\ORM;

class User extends ORM {

    public $primary_key = 'id';

    function _init() {

        self::$fields = array(
            'id' => ORM::field('auto[10]'),
            'username' => ORM::field('char[10]', array('required')),
            'password' => ORM::field('char[255]'),
            'email' => ORM::field('char[255]'),
        );
    }
}
?>


Controller :

Code:
$user = new Model\Members\User();
        $user->email = "[email protected]";
        $user->save();
        var_dump($user->errors);

No errors and my User is saved in my DB..I don't understand..
I use HMVC module for CI..
#96

[eluser]davidsoussan[/eluser]
How do I add multiple children to a new parent? Currently I am only getting the last child saved.

Code:
public function create_default_settings() {
  $default = array(
   array( 'setting' => 'module_downloads', 'value' => '1' ),
   array( 'setting' => 'module_kb', 'value' => '1' ),
   array( 'setting' => 'module_email', 'value' => '1' ),
   array( 'setting' => 'module_livechat', 'value' => '1' ),
   array( 'setting' => 'module_reporting', 'value' => '1' ),
   array( 'setting' => 'module_frontend', 'value' => '1' ),
   array( 'setting' => 'site_title', 'value' => $this->contact_company )
  );
  foreach ( $default as $val ) {
   $this->related->set( 'entities.settings.child', $val );
  }
}

This happens when I add them individually as well. Do I have to add them one by one and call save() each time?
#97

[eluser]seegithub[/eluser]
mas toopay saya tanya dong masalah eager loading, masih bingung soalnya dokumentasi nya gas masih sedikit banget.

saya punya
table account
fields:
- id
- username
- group_id

table group
fields:
- id
- group_name

settingan model account ke model group kan -> has_one, trus model group ke model account -> has_many nah saya coba melakukan query dengan code:
Code:
//saya mendapatkan semua records dari table account
$u = Account::with('group')->all();

ditable account kan ada group_id tuh mas, saya mau covert jadi nama group nya, saya gak mau join table karna akan menambah query lagi, trus kl me-looping foreach pake eager loading versi gas ORM ini bagaimana ya mas? mohon bantuannya. saya coba gini gak bisa:
Code:
foreach ($u as $d) {
            echo "username: {$d->username} | group: {$d->group->group_name}";
}

terima kasih banyak mas toopay
#98

[eluser]davidsoussan[/eluser]
[quote author="Thibaut L." date="1373471722"]Thanks it's working !

Another question, I try to use validation in my model like the documentation, but I am able to save my user in the database without setting username whereas I've set 'required'.


Code:
<?php

namespace Model\Members;

use \Gas\ORM;

class User extends ORM {

    public $primary_key = 'id';

    function _init() {

        self::$fields = array(
            'id' => ORM::field('auto[10]'),
            'username' => ORM::field('char[10]', array('required')),
            'password' => ORM::field('char[255]'),
            'email' => ORM::field('char[255]'),
        );
    }
}
?>


Controller :

Code:
$user = new Model\Members\User();
        $user->email = "[email protected]";
        $user->save();
        var_dump($user->errors);

No errors and my User is saved in my DB..I don't understand..
I use HMVC module for CI..[/quote]

It took me a while to figure this one out because it is on a different page: you have to padd TRUE into the save method to trigger validation.

Code:
$user = new Model\Members\User();
        $user->email = "[email protected]";
        $user->save( TRUE );
        var_dump($user->errors);

Now all I have to do is to figure out how to stop it throwing a validation error on fields that I define as nullable Smile
#99

[eluser]koichirose[/eluser]
Hi, I'm not sure if this topic is still active, but I'm having this issue:

Code:
if (!empty($deal->start_date)) {
echo $deal->start_date; //outputs nothing, does not enter the if
}

$start_date = $deal->start_date;

if (!empty($start_date)) {
echo $deal->start_date; //outputs the deal start date, enters the if
}

$deal is a Gas object, of course.

What is going on here?

Looks like the property is there and not empty, but somehow it doesn't work with empty(), and I'm guessing with other functions, too.

[eluser]koichirose[/eluser]
Hi, I don't understand how to fetch an object while filtering its related objects.

Example:
Code:
$this->data['sites'] = Model\Site::with('deal')->all(); //I'd like only deals with 'is_active=1' here, how do I do that?

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB