EllisLab text mark
Advanced Search
13 of 15
13
   
Gas ORM 2
Posted: 19 November 2012 12:12 PM   [ Ignore ]   [ # 191 ]   [ Rating: 0 ]
Joined: 2012-11-05
7 posts

@Kljofa

Hello,

What do you mean when you say multiple joins?  Do you mean one parent entity with many child entities, or a parent entity with a child entity, which in turn is the parent of another and so on.  For the first type of relationship the documentation gives good examples. First you need to set up the relationships so that gasorm knows how tables relate to each other:

http://gasorm-doc.taufanaditya.com/relationship.html

Once you have done that, you can use the with() function.  Here is an example from:

http://gasorm-doc.taufanaditya.com/quickstart.html

There is an entity called user, and the relationships between the (has many)kid, (has one)wife and (has many)job entities have been created so that the command below creates the joins and retrieves the corresponding records for all users.

$users Model\User::with('wife''kid''job')->all(); 

If there is a chain of parent/child entities, the above command could be used to get the initial parent/child relationship, then the command below can be used to fetch only the child entity details of further entities.

Model\Parent_entity_name::find(1)->child_entity_name(); 

Depending on the source of your download you may have to watch your capitalization as the link below discusses, as I vaguelly remember I had the problem with capitalization too first time round:

http://ellislab.com/forums/viewthread/213348/P120/#1010854

 

 
Posted: 19 November 2012 12:35 PM   [ Ignore ]   [ # 192 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1586 posts

@snowfall,

Its looks like the ORM class seeing your primary key as invalid collumn name, in the constructor.

Just to verify, ensure that ‘sample_context_refid’ is exists on below script output :

var_dump(Model\Tbl_sample_related_context::make()->meta->get('collumns'));die; 
 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 19 November 2012 12:47 PM   [ Ignore ]   [ # 193 ]   [ Rating: 0 ]
Joined: 2012-11-05
7 posts

@toopay

Result is:

array(3{ [0]=> string(20"sample_context_refid" [1]=> string(12"sample_refid" [2]=> string(14"context_number" 

The code nearly works, it is using the correct foreign key except it has the table name attached.  This is the malformed SQL:

SELECT FROM "tbl_sample_related_context" WHERE "tbl_sample_related_context"."tbl_sample_sample_refid" IN (2

This is what it *should* be when correct:

SELECT FROM "tbl_sample_related_context" WHERE "tbl_sample_related_context"."sample_refid" IN (2
 
Posted: 19 November 2012 12:56 PM   [ Ignore ]   [ # 194 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1586 posts

@snowfall.

I can’t replicate this behaviour, since custom foreign key actually already well-covered within recent unit-test suite.

I suspect, the ORM class going down to this line while investigating your entity meta-data.

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 19 November 2012 01:57 PM   [ Ignore ]   [ # 195 ]   [ Rating: 0 ]
Joined: 2009-12-23
4 posts

Here is a crude example of my problem.

I have 3 tables

TABLE 1
id
year

TABLE 2
id
table1_id

TABLE 3
id
table2_id

I want to grab all results from table 3 that matches year from table 1.

I tried doing something like this:

$table3 Model\Table3::join('table2''table2.id = table3.table2_id')->join('table1''table1.id = table2.table1_id')->find_by_year(2012); 

but i only get one join and that’s the last one i entered. Relationships are properly set.

 
Posted: 19 November 2012 03:13 PM   [ Ignore ]   [ # 196 ]   [ Rating: 0 ]
Joined: 2012-11-05
7 posts

@toopay

Found the problem.  In the child relation, if capital letters are used for Model and Class, it fails.  So this causes the problem:

public $foreign_key = array('\\Model\\Tbl_sample' => 'sample_refid'); 

But if lower case letters are used, it passes.  This solves the problem:

public $foreign_key = array('\\model\\tbl_sample' => 'sample_refid'); 

Raised before, http://ellislab.com/forums/viewthread/213348/P120/#1010854 but I, was using the code from Github, so thought it would be fine. D’oh.  Thanks for looking, sorry to disturb ^^

 
Posted: 19 November 2012 10:07 PM   [ Ignore ]   [ # 197 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1586 posts

@Kijofa

If everything has been setup correctly, you should only need :

$table1 Model\Table1::with('table3')->find_by_year(2012); 
$table3 $table1->table3(); 

You do not need to set up a manual JOIN.

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 20 November 2012 04:23 AM   [ Ignore ]   [ # 198 ]   [ Rating: 0 ]
Joined: 2009-12-23
4 posts

Tried that but didn’t work. This is what i have setup in my models.

TABLE 1 model:

self::$relationships = array('table2' => ORM::has_many('\\Model\\Table2')); 

TABLE 2 model:

self::$relationships = array('table1' => ORM::belongs_to('\\Model\\Table1'), 'table3' => ORM::has_many('\\Model\\Table3')); 

TABLE 3 model:

self::$relationships = array('table2' => ORM::belongs_to('\\Model\\Table2')); 

With this relationship i tried calling the code you mentioned but got error that the method doesn’t exists in the object.

 
Posted: 20 November 2012 12:23 PM   [ Ignore ]   [ # 199 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1586 posts

@Kijofa

With your current setup, this should do the job :

$table1 Model\Table1::with('table2')->find_by_year(2012);

foreach (
$table1->table2() as $table2)
{
  var_dump
($table2->table3());

Actually, it is easier to set up :

// In table1
self::$relationships = array('table3' => ORM::has_many('\\Model\\Table2 <= \\Model\\Table3')); 

so that you could use the previous code i mention.

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 10 December 2012 11:07 AM   [ Ignore ]   [ # 200 ]   [ Rating: 0 ]
Joined: 2012-11-01
5 posts

Hi.

I have a pivot table set up. I want to fetch data from a table connected to the pivot table using the result extension but i want to check if the id is valid against the pivot table.

 
Posted: 14 December 2012 08:25 AM   [ Ignore ]   [ # 201 ]   [ Rating: 0 ]
Joined: 2012-03-22
11 posts

After upgrading from GORM 2.0.0 to 2.1.1 the following code no longer works for me:

Model\User::with('userdata')->all(); 

It used to do a subquery:

SELECT FROM `userdataWHERE `userdata`.`user_idIN 1,2,3,4,5,

But now instead it does

SELECT FROM `userdataWHERE `userdata`.`user_idIN 

and every other $user->userdata() will return bool False.

I.e. it only queries the userdata table for the last row matched in the user table.

I can still loop through the list of users and print their IDs and check by hand that they match the ones in the database, so that should not be a problem.

What am I doing wrong here?

 
Posted: 31 January 2013 06:14 AM   [ Ignore ]   [ # 202 ]   [ Rating: 0 ]
Joined: 2012-11-01
5 posts

I have three tables. Jobs, Categories and Location. I want to find jobs with a sertain category id and location id. Jobs has many categories and categories has many jobs. Therefore i need to use a pivot table. I checked out laravels ORM and in there you used:

$jobs Jobs::with(array('locations' => function($query)
{
    $query
->where('id''like'1);

}))->get(); 

Are there any ways to do something similar with GAS?

 
Posted: 13 February 2013 12:30 PM   [ Ignore ]   [ # 203 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1586 posts

Patch v.2.1.2

Changes :
1. Fixes several known issues on relationship entities.
2. Minor refactor on Core class.
3. Additional files on test-suite to cover core files.

How to update :
If you previously download the zipped files, just re-download and replace the old one. If you already installed via Spark, update using this command from your comman line :

php tools/spark reinstall -v2.1.2 gas 

I added a section on README about test-suite, so make sure to read that section before tweeting me any issues regarding this open-source library. smile

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 23 February 2013 03:03 PM   [ Ignore ]   [ # 204 ]   [ Rating: 0 ]
Joined: 2013-02-23
1 posts

Hello! How can I get a result, as I’m make a query:
SELECT * from USER WHERE user_email = ‘Arugin’ AND user_password=“123”

I’m trying to write something like this:

$data = User::where(“user_email =”,$user_email)->first()->where(“user_password =”,$user_password)->first();

but it’s ignore the first “where”.

What I’m missed?

Thank you.

 
Posted: 25 February 2013 07:20 AM   [ Ignore ]   [ # 205 ]   [ Rating: 0 ]
Avatar
Joined: 2010-01-07
6 posts

Hi toopay,

I have some problems using relationships into GAS.
I basically have two tables:

chef_secteur {id[int], nom_cs[var_char], email_cs[int]}
1 | John Doe | 1
2 | Ana Alba | 3

users {id[int], identity[varchar], pass[varchar], email[varchar]}
1 | jd | xxx | jdoe at tt.co
2 | ue| xxx | ultra at tt.co
3 | aa | xxx | aalba at tt.co

So the `chef_secteur`.`email_cs ` belongs to the `users`.`email`

These are my GAS models : http://codepad.org/kQynbVeo
I get a server NetworkError: 500 Internal Server Error hangout when I add fields in relationships array. If I comment them, GAS 2.1.2 works fine, I’m using it as result()->find_by_field() and I’m happy with it.

Thanks, Radu

 
13 of 15
13