⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

set_relation_n_n gives me jQuery error, how to fix?



kaosweaver
  • profile picture
  • Member

Posted 20 August 2012 - 15:00 PM

Ok, so I've setup a news table and a hashtag table and a table between them (news, tags, news_x_tags).
I setup the news CRUD and it worked just fine:


$this->load->library('grocery_CRUD');
$crud = new grocery_CRUD();

$crud->set_table('news')
->set_subject('News')
->columns('news_title','news_content','news_publish_on','news_author')
->display_as('news_title','Title')
->display_as('news_content','Content')
->display_as('news_publish_on','Publish Date')
->display_as('news_author','Author');

$crud->order_by('news_publish_on','desc');

$crud->required_fields('news_title','event_tnews_contentype','news_publish_on','news_author');

$data['output'] = $crud->render();


When I add the following (under the ORDER BY line), it renders correctly:

$crud->set_relation_n_n('news','news_x_tags','tags','news_id','tag_id','tag_name','taggedby')
->display_as("news","Tags");


However, when I go to submit, I get:

[indent=1]
Timestamp: 8/20/2012 9:53:04 AM
Error: SyntaxError: JSON.parse: unexpected character
Source File: http://myserver.com/assets/grocery_crud/js/jquery-1.7.1.min.js
Line: 2
[/indent]

What do I need to change in order to get this to function as expected? I appreciate your help.

kaosweaver
  • profile picture
  • Member

Posted 23 August 2012 - 13:05 PM

No ideas anyone?

goFrendiAsgard
  • profile picture
  • Member

Posted 23 August 2012 - 15:20 PM

You have "news" as table name, and "news" as the first parameter of set_relation_n_n.
The set_relation_n_n require the first parameter to be field, not table
Can you try to use this:


$this->load->library('grocery_CRUD');
$crud = new grocery_CRUD();

$crud->set_table('news')
->set_subject('News')
->columns('news_title','news_content','news_publish_on','news_author','x')
->display_as('news_title','Title')
->display_as('news_content','Content')
->display_as('news_publish_on','Publish Date')
->display_as('news_author','Author');

$crud->set_relation_n_n('x','news_x_tags','tags','news_id','tag_id','tag_name','taggedby')
->display_as("x","Tags");

$crud->order_by('news_publish_on','desc');
$crud->required_fields('news_title','event_tnews_contentype','news_publish_on','news_author');

$data['output'] = $crud->render();

kaosweaver
  • profile picture
  • Member

Posted 27 August 2012 - 13:10 PM

Thanks for the tips, I figured it out by seeing the reply, apparently, the user for the DB I'd setup didn't have permissions on one of the tables, so when the update happened, it returned a mysql/php error and the code didn't report it back as an error. Changed the user to the right one with permissions and - wow - it worked! Again, thanks for the tips, I appreciate the help.