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

[eluser]toopay[/eluser]
@Jazmo,
If i correctly get what you are trying to do, this schema will allow you to do it better :
Code:
+---------------+   +--------------+   +------------+
| reserve       |   | reserve_type |   | room       |
+---------------+   +--------------+   +------------+
| id            |<->| reserve_id   |   |            |
| other_field   |   | room_id      |<->| id         |
| ...           |   | other_id     |   | info       |
+---------------+   +--------------+   | .........  |
                                       +------------+
reserve_type act as pivot table that could bridge reserve to room and other table(s). other_id could reference to other table as well, and you could set up several related entities with different type of relationship(s), within reserve model using through option.
#42

[eluser]Jazmo[/eluser]
Good idea toopay! Thanks for your help.
#43

[eluser]mecharius[/eluser]
[quote author="toopay" date="1329131027"]@mecharius, i cant reproduce those weirdness.

What happen if you change
Code:
$perm = new Permissions;
above into
Code:
$perm = Gas::factory('permissions');

If the weirdness still occur, i will need to see more chunk of code you use, around those saving process, to do some debugging trace.
[/quote]

Hi Toopay, sorry for the late reply... very busy week. I just changed the code to use
Code:
Gas::factory('xxxxx');
but it still does the same thing. Very weird - it only does it creating permissions for one particular model. This happens even if I don't pass the permissions function that model - i.e. just an integer ID to grant permission to.

My current work around is just to add a "created_at" column in the database which is mostly nulls. I'll post back here if I work it out.

Thanks! Will
#44

[eluser]Khrome83[/eluser]
Hi,

I have a controller class names Skills, as well as a table names skills.

So when it auto-generated my Models, I have a model named skills.

So when I go to the Skills controller, I get a error -

Quote:Fatal error: Cannot redeclare class Skills in /mounted-storage/home71b/sub007/sc41106-WCWU/guildwars/application/models/skills_gas.php on line 59

I assume I can rename my class for the model. But what is a safe naming scheme, or is there a configuration mistake I made for gas?
#45

[eluser]toopay[/eluser]
@Khrome83,
Actually, that was one cons of version 1.x.x of this package. The only thing you could do right now, is to choose different class name.

In version 2.x.x, Gas resolve this using what already provided by PHP 5.3, namespace. Version 2.0 of this package is already done, and ready to be used (personally i already use version 2.0 of Gas ORM in my production application), it just that i did not write/update the documentation yet. Soon i will update them, so everyone could start use this new version.
#46

[eluser]Khrome83[/eluser]
I can't wait for the new version. I have read some of your posts about 2.0 and it sounds a large step forward.

In 1.x.x there is no issues with me renaming the model class name? In the relationships I declare them by Model name not Table name correct? So if I change it, I need to modify the relations to match?

On a side note, the auto-create models also created models for the Pivot tables, I kept them and added belongs_to to the relations information for them. Was this the correct way to handle it (like RoR)?
#47

[eluser]toopay[/eluser]
[quote author="Khrome83" date="1331390347"]
In 1.x.x there is no issues with me renaming the model class name? In the relationships I declare them by Model name not Table name correct? So if I change it, I need to modify the relations to match?
[/quote]
Indeed.
[quote author="Khrome83" date="1331390347"]
On a side note, the auto-create models also created models for the Pivot tables, I kept them and added belongs_to to the relations information for them. Was this the correct way to handle it (like RoR)?[/quote]
It has nothing to do with RoR, but yes you're doing it right.
#48

[eluser]Khrome83[/eluser]
When auto creating models, is there anything that is cached? I had a type-o in a column name in the Pivot table, but fixed it. Now every other relationship and model works well, with the exception of the table that had a type-o.

When access contents of the table directly it works -

Code:
$profs = Gas::factory('professions')->all();

   foreach($profs as $bar) {
    echo '<br /><br />';
    echo 'Professions - '.$bar->name;
    //echo print_r($bar);

   }

When accessing it through skills -

Code:
$skills = Gas::factory('skills')->all();

   foreach($skills as $skill) {
    echo 'Skill Name Found - '.$skill->name;
    echo '<br /><br />';
    //echo print_r($skill);
    echo wtf($skill);

    foreach($skill->professions as $p){
     echo '<br /><br />';
     echo 'Profession Requirement - '.$p->name;
     echo '<br /><br />';
    }
}

I tried to use with('professions') when accessing skills with no luck as well. All other relationships set up the same way work fine. I checked all models for any type-o's that were created because of my earlier error.

Skill Relationships -
Code:
class Skills extends Gas {

public $table = 'skills';

public $primary_key = 'id';

    public $relations = array(
       'has_many' => array('pets' => array('through' => 'skills_pets'),
            'races' => array('through' => 'skills_races'),
            'types' => array('through' => 'skills_types'),
            'professions' => array('through' => 'skills_professions'),
            'sets' => array('through' => 'skills_sets')
          )                                                                          
    );

Professions Relationships -

Code:
class Professions extends Gas {

public $table = 'professions';

public $primary_key = 'id';

    public $relations = array(
        'has_many' => array('skills' => array(
                   'through' => 'skills_professions',
                        )),
    );

Pivot Table Relationships -

Code:
class Skills_professions extends Gas {

public $table = 'skills_professions';


public $primary_key = 'id';

    public $relations = array(
        'belongs_to' => array('skills' => array(),
               'professions' => array()
            ),
    );
#49

[eluser]toopay[/eluser]
In skills_professions table, do you have both skills_id and professions_id collumn(s) ? If you have the singular name, eg skill_id, you will also need to specify foreign_key option within your relationship definition.
#50

[eluser]Khrome83[/eluser]
I have the pivot table have a id field, skills_id and professions_id. Both plural. Its almost like something is being cached. I have several other relationship set up that work great. Is there a character limit for table or model names ir foreign keys?





Theme © iAndrew 2016 - Forum software by © MyBB