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

Hi Toopay,

I had already made the change to core.php, I tried using the core.php you linked to in case there were other changes but it still doesn’t work. 

With the code I posted you can see that the all() method works one way along the relationship with the patch, but not the other.  I put the behaviour that’s failing also at the bottom of the post, where with

$token.$original_id 

$token points towards the correct values in $holder

lkpsite:manager_refid 

However $original_id points towards the primary key value (a site_code value), and not the foreign key value (a manager_refid value) which would produce an array result.

Thanks for the help smile

 
Posted: 06 November 2012 02:42 PM   [ Ignore ]   [ # 182 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1586 posts
snowfall - 06 November 2012 07:12 AM

However $original_id points towards the primary key value (a site_code value), and not the foreign key value (a manager_refid value) which would produce an array result.

Gotcha. I’ve just update the previous patch for core.php : https://gist.github.com/4023670

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 06 November 2012 04:23 PM   [ Ignore ]   [ # 183 ]   [ Rating: 0 ]
Joined: 2012-11-05
7 posts

@toopay

Thanks for the reply.  The issue with the category model is that the relationships are in a separate table, so I can’t query the category table directly.  Each category can have multiple parents, and multiple children

 
Posted: 06 November 2012 04:26 PM   [ Ignore ]   [ # 184 ]   [ Rating: 0 ]
Joined: 2012-11-05
7 posts

@toopay

And if there’s no way to modify the query on the foreign table through the pivot table, how would you recommend I execute a more complex query on it?  I guess I’ll have to bypass the built-in relationship functionality.

Thanks

 
Posted: 06 November 2012 05:54 PM   [ Ignore ]   [ # 185 ]   [ Rating: 0 ]
Joined: 2012-11-05
7 posts

Is there a way to chain multiple where() clauses together?  I’ve tried it, but only the last clause is in the query.

$categories \Model\Categories::make()->where('priority >'2)->where('author'482)->all();
// Will only run 'SELECT * FROM category WHERE author = 482' 
 
Posted: 07 November 2012 03:51 AM   [ Ignore ]   [ # 186 ]   [ Rating: 0 ]
Joined: 2012-11-01
5 posts

When i updated the core, this error started showing:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘“event_images” WHERE “event_images”.“events_id” IN (1, 2, 3, 4, 5, 6, 7, 8, 9)’ at line 1

SELECT * FROM “event_images” WHERE “event_images”.“events_id” IN (1, 2, 3, 4, 5, 6, 7, 8, 9)

My guess is that the double quotes carries the problem!

 
Posted: 07 November 2012 04:26 AM   [ Ignore ]   [ # 187 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1586 posts

Updated patch : https://gist.github.com/4023670 (i’ve added backward compability within `generate_clause` method, as @necken issue emerged).

Soon i have enough time i will wrap those patch with appropriate unit-test files, and merge that into the main repo. Report any issue with this patch, if any.

@jonahdahlquist,

And if there’s no way to modify the query on the foreign table through the pivot table, how would you recommend I execute a more complex query on it

Only ‘select’, ‘limit’ and ‘order_by’ clauses which were supported, right now. That were more than enough for me smile

Regarding ‘where’ clause, ‘where’ method is accept three type of parameters. First you could passed a string :

$categories \Model\Categories::make()->where("priority > 2 AND author = 482")->all(); 

Then you could also passed an array. So theres no need to chain ‘where’ with other ‘where’, since it will overwrite current recorder with the last one. But you COULD, chaining ‘where’ with ‘or_where’. For further detail, check this test case

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 09 November 2012 09:43 PM   [ Ignore ]   [ # 188 ]   [ Rating: 0 ]
Joined: 2012-11-05
7 posts

@Toopay,

Thanks for the patch, it works perfectly grin <edit> I had a brief look but could not see in the source just now, when passing the $POST data to create a record does gasorm escape the data, or perform the XSS check?  If not, is there a point in the code you would recommend to add it, so it performs on all data supplied for insert/update and where fields. </edit>

 
Posted: 19 November 2012 10:14 AM   [ Ignore ]   [ # 189 ]   [ Rating: 0 ]
Joined: 2012-11-05
7 posts

Hi Toopay, another bug I think.

After applying the patches I have this error:

ERRORcolumn tbl_sample_related_context.tbl_sample_sample_refid does not exist LINE 1SELECT FROM "tbl_sample_related_context" WHERE "tbl_sample... ^

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

Filename: /var/ci/application/third_party/gas/classes/core.php

Line Number: 839 

In the Where clause after the period it wrongly puts the table name connected to the primary key, it uses ‘tbl_sample_sample_refid’ when it should only be ‘sample_refid’.

The relationships appear set up properly as are the primary/foreign key values in both models.


Calling Line:

$data['sample'Model\Tbl_sample::where("site_code = '".$site_code."' AND sample_number = ".$sample_number)->with('related')->all(); 

Also same error with ->get(1) instead of ->all().

Tbl_sample exert:

class Tbl_sample extends ORM {
 

        
public $primary_key 'sample_refid';

 function 
_init()
 
{

                self
::$relationships = array (
                        
'monolith'          =>     ORM::has_one('\\Model\\Tbl_sample_monolith'),
                        
'processed'          =>     ORM::has_one('\\Model\\Tbl_processing'),
                        
'series'          =>     ORM::has_one('\\Model\\Tbl_sample_series'),
                        
'children'          =>     ORM::has_many('\\Model\\Tbl_parent_sample'),
                        
'location'          =>     ORM::has_many('\\Model\\Tbl_sample\\Tbl_sample_location'),
                        
'purpose'          =>     ORM::has_many('\\Model\\Tbl_sample_secondary_purpose'),
                        
'related'          =>     ORM::has_many('\\Model\\Tbl_sample_related_context'),
                ); 

Tbl_sample_related_context exert:

class Tbl_sample_related_context extends ORM {
 
        
public $primary_key 'sample_context_refid';
        public 
$foreign_key = array('\\Model\\Tbl_sample' => 'sample_refid');

 function 
_init()
 
{


                self
::$relationships = array(
                        
'sample' => ORM::belongs_to('\\Model\\Tbl_sample'),
                ); 
 
Posted: 19 November 2012 11:33 AM   [ Ignore ]   [ # 190 ]   [ Rating: 0 ]
Joined: 2009-12-23
4 posts

Hi,

started using Gas ORM today and am very pleased with it, but am having trouble with something. I don’t know how to do multiple join statements. Searched everywhere but was not able to find solution.

Thanks

 
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.

 
13 of 15
13