0

i wrote a query to retrieve values from database by joining two table, but it throws error.

following is the SQL query which i have written.

if ($selected_key_type != null ) {
    $o = ORM::factory('organization')->join_table('keywords_organization','keywords_organization.organization_id', 'organization.id')->where('keywords_organization.keyword_id',$selected_key_type);


    }

Following is the error being displayed

Fatal error: Call to a member function where() on a non-object in /var/www/xxxx/html/application/controllers/organizations.php on line 51

Any help would be appreciated :)

  • That means that the part before *where* is not an object: it's maybe *null*, or a string, or a boolean, etc. What's the output of `var_dump(ORM::factory('organization')->join_table('keywords_organization','keywords_organization.organization_id', 'organization.id'))`? – Samy Dindane May 17 '12 at 18:58
  • string(35) "keywords_organization_organizations" is the output – vijayvarma555 May 17 '12 at 19:06
  • What about `$o = ORM::factory('organization')->join_table('keywords','keywords.organization_id', 'id')`? – Samy Dindane May 17 '12 at 19:45

3 Answers3

0

The syntax you are using in incorrect.

It should be:

$o = ORM::factory('organization')
    ->join('keywords_organization','LEFT')
    ->on('keywords_organization.organization_id', '=', $selected_key_type)
    ->find_all();

Source: https://stackoverflow.com/a/5685379/604041

Community
  • 1
  • 1
Samy Dindane
  • 17,900
  • 3
  • 40
  • 50
0

join_table takes one parameter join_table('table_name') which is use to create pivot table. So i guess you are trying to use join() NOT join_table().

Kohana 2.3.4 ORM pivot table query

Community
  • 1
  • 1
Rojan
  • 247
  • 3
  • 6
0

join_table() isn't what you were looking for. join() is the correct method and is part of the query builder in Kohana 2+. FYI join_table() uses alphabetical comparison to choose the name of the join table. Therefore it is a method which returns a value other than $this. Chainable methods $class->method1()->method2()->method3() return $this which is what makes them chainable. Im a Kohana 3.2 user and if your original code from above is correct minus the join part, this should work.

if ($selected_key_type != null ) {
    $o = ORM::factory('organization')
        ->join('keywords_organization','keywords_organization.organization_id', 'organization.id')
        ->where('keywords_organization.keyword_id',$selected_key_type);
}

You can also add a fourth parameter to join() that specifies the type of join you want to create. See http://docs.kohanaphp.com/libraries/database/builder#join for more details.

pogeybait
  • 3,065
  • 2
  • 21
  • 23