⚠ 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 not working right?



gavin
  • profile picture
  • Member

Posted 18 July 2012 - 22:08 PM

Hi,

first off: awesome, awesome, AWESOME piece of code! This will make my coding life so much easier. Thank you :)

Ok, I'm playing around with the code but I'm running into something odd. I have 2 tables :

[b]bitauth_users[/b]
- user_id
- username
- etc

[b]bitauth_userdata[/b]
- userdata_id
- user_id
- full_name

I set
$crud->set_table('bitauth_users');
$crud->set_relation('user_id','bitauth_userdata','fullname');
but nothing happens. Printing the sql gives me
SELECT `bitauth_users`.*, je8701ad4.fullname AS se8701ad4 FROM (`bitauth_users`) LEFT JOIN `bitauth_userdata` as je8701ad4 ON `je8701ad4`.`userdata_id` = `bitauth_users`.`user_id` LIMIT 25


As you can see it refers to userdata_id instead of user_id. Is this a bug or am I missing something?

EDIT: Ok, I've set
$crud->set_primary_key('user_id','bitauth_userdata');
and this returns the correct query
SELECT `bitauth_users`.*, je8701ad4.fullname AS se8701ad4 FROM (`bitauth_users`) LEFT JOIN `bitauth_userdata` as je8701ad4 ON `je8701ad4`.`user_id` = `bitauth_users`.`user_id` LIMIT 25


But still I don't see the dropdown (which I believe I should see) on the edit screen.

gavin
  • profile picture
  • Member

Posted 18 July 2012 - 22:36 PM

Never mind. I got the concept backwards.

I believe I should be looking at a 1-1 relation instead of 1-n. But how can you get the userdata that's in a different table and edit it on the same screen?

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 19 July 2012 - 06:34 AM

Well unfortunately I am sorry to tell you that this is the feature set_relation_1_1 that grocery CRUD doesn't support it yet.

gavin
  • profile picture
  • Member

Posted 19 July 2012 - 08:59 AM

Ok thanks. But you say 'yet'. Is this on the todo list?

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 21 July 2012 - 22:09 PM

Well it is now https://github.com/scoumbourdis/grocery-crud/issues/75 :) I have all of these issues just to remind me what I have to do. As for 1.3 version this is not planned to be ready as it need lot of time and its a bit complicated.
In addition the 1.3 version will be a big release and I already planned to do many important new features ( such as exporting and printing ) and I don't thing I will have time for that.

Kindest Regards

Johnny

nsahid
  • profile picture
  • Member

Posted 22 July 2012 - 09:29 AM

I have problem too ...

[b]bmt_dataorangtua[/b]
- id_ortu
- id_peserta
- ayah_nama
- ayah_pekerjaan
- ibu_nama
- ibu_pekerjaan
- kontak
- alamat


[b]bmt_datapribadi[/b]
- id_peserta
- noinduk
- nama_lengkap
- peserta_aktif
- tmp_lahir
- tgl_lahir
- jenis_kelamin

[b]bmt_data_pekerjan[/b]
- id_pek
- pekerjaan


my controller : orangtua.php
	$crud->set_theme('datatables');
$crud->set_table('bmt_dataorangtua');
$crud->set_subject('Data Orang Tua');

$crud->display_as('id_peserta','Nama Siswa')
->display_as('nama_ayah','Nama Ayah')
->display_as('ayah_pekerjaan','Pekerjaan Ayah')
->display_as('nama_ibu','Nama Ibu')
->display_as('ibu_pekerjaan','Pekerjaan Ibu');
//Add data
$crud->fields('id_peserta','nama_ayah','ayah_pekerjaan','nama_ibu','ibu_pekerjaan','kontak','alamat');
$crud->required_fields('id_peserta','nama_ayah','nama_ibu','kontak','alamat');

$crud->columns('id_peserta','nama_ayah','ayah_pekerjaan','nama_ibu','ibu_pekerjaan','kontak','alamat');

//melakukan relasi data orang tua
$crud->set_relation('id_peserta','bmt_datapribadi','nama_lengkap');

$crud->set_relation('ayah_pekerjaan','bmt_data_pekerjaan','pekerjaan');


view: ... OK
try to fill incorrect data ...
result : ... OK

But ... fill with correct data ...
Result: NOT INSERT TO DATABASE bmt_dataorangtua

PLEASE HELP ME...

OK... i attach screenshot

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 22 July 2012 - 09:37 AM

Hello [member='nsahid'] and welcome to the forum.

Please check your firebug response for this error it will be really helful to check what is the AJAX response for this. This will help you a lot to understand what the problem is. If you still cannot figure out what the problem is, just post to us an image that looks like this [attachment=234:2012-07-22_103541.png]

Regards

Johnny

nsahid
  • profile picture
  • Member

Posted 23 July 2012 - 05:26 AM

Thank you ... problem solved ...
Sorry I was wrong to write the field name

This is firebug screen shot ...
[img]http://dc594.4shared.com/img/JjpYi8cQ/0.015112020393965309/firebug_fix.png[/img]