Welcome Guest, Not a member yet? Register   Sign In
natural join with CI Active Record
#5

[eluser]roryokane[/eluser]
I'm afraid this doesn't work for me. With the code
Code:
$query = $this->db->select('title, description, length(audio), realname, creationdate, podid')->from('podcasts NATURAL JOIN users')->where('userid', $this->uri->rsegment(4) )->get();
I get this error:


Quote:A Database Error Occurred

Error Number: 1064

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 'JOIN` users) WHERE `userid` = '4'' at line 2

SELECT `title`, `description`, length(`audio`), `realname`, `creationdate`, `podid` FROM (`podcasts` NATURAL `JOIN` users) WHERE `userid` = '4'


As you can see, the "JOIN" was quoted and "users" was not. Maybe an update of CodeIgniter stopped this from working.

What I'd really like to do, and wish CodeIgniter could do, is say something like
Code:
$this->db->from('podcasts')->join('users', 'NATURAL')
or perhaps even
Code:
$this->db->from('podcasts')->join('users')

I'm having trouble working around this problem without just using $this->db->query(). When I change the middle of the query to
Code:
->from('podcasts')->join('users', 'users.userid = podcasts.userid')
, I get this error:


Quote:A Database Error Occurred

Error Number: 1052

Column 'userid' in where clause is ambiguous

SELECT `title`, `description`, length(`audio`), `realname`, `creationdate`, `podid` FROM (`podcasts`) JOIN `users` ON users.userid = podcasts.userid WHERE `userid` = '4'
, even though I made sure to specify the column names (though stupid MySQL 5.0.41 should be able to realize that the result will be the same after the join).

Can anyone help with either of these problems, or tell me how I would officially request or write myself (for the official release) the modification to join()? (I'm not sure if a bug report is appropriate.)


Messages In This Thread
natural join with CI Active Record - by El Forum - 05-16-2008, 04:48 PM
natural join with CI Active Record - by El Forum - 05-16-2008, 04:59 PM
natural join with CI Active Record - by El Forum - 05-16-2008, 05:04 PM
natural join with CI Active Record - by El Forum - 05-16-2008, 05:24 PM
natural join with CI Active Record - by El Forum - 09-09-2008, 01:39 AM
natural join with CI Active Record - by El Forum - 09-09-2008, 02:34 AM
natural join with CI Active Record - by El Forum - 09-09-2008, 02:38 AM
natural join with CI Active Record - by El Forum - 09-11-2008, 06:17 AM
natural join with CI Active Record - by El Forum - 09-16-2008, 10:32 AM



Theme © iAndrew 2016 - Forum software by © MyBB