⚠ 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 rules not working on set_relation



mavershim
  • profile picture
  • Member

Posted 12 May 2012 - 03:37 AM

hi,

i dont know if this is a bug or i just happen to have a wrong code. I have this on my code


$crud->set_relation('serialNo','printers'.'serialno');
$crud->set_relation('refNo','fsr','srno',array('status'=>'pending','status'=>'New','status'='Schedule'));
$crud->set_rules('serialNo','Serial No','required')
->set_rules('refNo','Reference','requied');



1. the set_relation will only show rows whose status = 'Schedule' but will not consider the first 2. is there a way to make it show status = pending or new or schedule.

2. on my add section even if I did not choose on the dropdown it will still save the entry it will disregard the rules validation.

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

Posted 14 May 2012 - 21:03 PM

It seems that your code is wrong the correct one is:


$crud->set_relation('serialNo','printers','serialno');
$crud->set_relation('refNo','fsr','srno',array('status'=>'pending','status'=>'New','status'=>'Schedule'));
$crud->required_fields('serialNo','refNo');
$crud->display_as('serialNo','Serial No')->display_as('refNo','Reference');

mavershim
  • profile picture
  • Member

Posted 16 May 2012 - 02:39 AM

Hi Johnny,

1. Used your code but still it save the data.


$crud->set_relation('serialNo','printers','serialno');
$crud->set_relation('refNo','fsr','srno',array('status'=>'pending','status'=>'New','status'=>'Schedule'));
$crud->required_fields('serialNo','refNo');
$crud->display_as('serialNo','Serial No')->display_as('refNo','Reference');


- This still add data to database. Did not validate the required fields.
2. On the set_relation only the last segment of data is considered.


$crud->set_relation('refNo','fsr','srno',array('status'=>'pending','status'=>'New','status'=>'Schedule'));



will only get rows with status = 'Schedule'.
It would be nice if it will get all data whose values are on the list of array.

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

Posted 16 May 2012 - 06:33 AM

Try this:


$crud->set_relation('refNo','fsr','srno',"status = 'pending' OR status = 'New' OR status = 'Schedule'");

mavershim
  • profile picture
  • Member

Posted 17 May 2012 - 01:35 AM

Hi Johnny,

Thanks for the prompt reply I have tried that before posting the problem. But everytime I used string on the 4th parameter it always consider it as a field name. I have attached a screenshot of the error. I dont know why it always enclosing string by this char `. By the way required_fields still not working for me. Still saving data even if the user did not select option on the dropdown. I think I will make a callback_before_insert as a temporary solution.

Thanks,

Mavershim

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

Posted 17 May 2012 - 20:05 PM

That's ... weird

Can you do a simple thing?

Can you just run (anywhere it doesn't matter):


$this->db->where("status = 'Pending' OR status = 'New' OR status = 'Schedule'");
$results = $this->db->get('fsr')->result();
echo "<pre>".print_r($results,true)."</pre>";
die();


Is this working for you? Perhaps it is a bug of Codeigniter what can I say. What CI version do you use?

mavershim
  • profile picture
  • Member

Posted 19 May 2012 - 00:34 AM

Hi,

That's weird the code you posted works. it shows all records with all the status listed. but in GC it doesn't. My CI version is 2.1.0 and my GC version is 1.2

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

Posted 19 May 2012 - 08:16 AM

It doesn't make sense. I do exactly the same thing.
1. Can you have a new project just to test this code if it works for you?
2. If no can you just update the grocery CRUD from 1.2 to 1.2.2 (please copy ALL the files and not just the library)? I don't thing that this will fix the problem but you never know
3. If still it doesn't work for you ... can you post your table structure and once again the function that you try to run (just copy paste it)?

mavershim
  • profile picture
  • Member

Posted 22 May 2012 - 06:55 AM

Hi,

I don't know what happen but now it's working. Thanks a lot and keep up the good job.