• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problems with Active Record

That doesn't make sense. I see no occurrences of jpp anywhere in your query. What am I missing?

Its set as the default table prefix in my config file...can I not use a default prefix?

Oh, I see! OK, Well looking at the source code, it looks like it won't add the prefix to aliases if you use AS with your aliases.

Could you give me an example? Sorry to be such a pain!

$this->db->from('gamedb AS g'); # Note the 'AS'.

Try that. You may have to do it with each alias in the select statement too, but we'll soon see. Hopefully it should get rid of the error you're currently getting however.

Tried adding AS to just that section, the select clause and the join clause and none of it resolved the error of it adding the table prefix to the join query Sad

OK, try passing FALSE as the second parameter for $this->db->from().

Ok I finally figured it out. The problem was the order of my db statements. I needed to do the from call before the join call because it was using the alias established in the from call. See code below:

$this->db->select('g.game_id as game_id, g.title as game_title, g.platform_id as platform_id, p.name as platform', FALSE);

$this->db->from('gamedb AS g'); # Moved this before the Join Statement

$this->db->join('gameplatforms p', 'p.platform_id = g.platform_id');

But thanks very much for working through this with me!

No problem. That's very strange, as all the AR class does is build a query string, it doesn't care about aliases or anything like that, it lets the database worry about that. Anyhow, glad you got it sorted.

Interesting... That may be an issue that needs to be addressed...

AR protects the identifiers... so it does keep track of the aliases... but obviously it doesn't know about the alias until the from function is called... And doesn't go back and update the query when the from function is called with an alias...

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.