⚠ 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

How to add two more fields when I edit a record, and update another table also



kenshicu

kenshicu
  • profile picture
  • Member

Posted 16 March 2013 - 23:40 PM

How to add two more fields when I edit a record, and update another table also


In order to normalize the database and avoid duplicate fields need to make this change in the structure of the database:


trabajadores_before.jpg
after:
trabajadores_after.jpg

As seen, i remove  id_provincia and id_municipio fields of trabajador table, and then it will not leave these fields when adding or editing the main table (trabajador) with GC.


How do I keep these two fields to add or edit records.


And in edit record of trabajdor table, as knowing the id_municipio and id_provincia through id_consejo_popular ? :wacko:


davidoster

davidoster
  • profile picture
  • Member

Posted 19 March 2013 - 15:48 PM

What do you mean remove? Not including them when you call the fields function?

If this is what you mean then your way of thinking isn't probably correct.

 

What I see from the first part (before as you declare it) of your DRD is that trabajador table has 3 foreign keys,

id_consejo_popular,

id_municipio and 

id_provincia

 

For Grocery CRUD to work correctly you need to setup three (3) different set_relation functions.

By the time you do this you don't need to worry about anything else since internal integrity of the tables is fully syncronized

(because of the 1-n relation between trabajador->consejo_popular, trabajador->provincia, trabajador->municipio).

 

I hope this helps you.


kenshicu

kenshicu
  • profile picture
  • Member

Posted 19 March 2013 - 16:12 PM

<p><span><span>Yes, I understand</span> <span>that, but</span> <span>as</span> <span>I need this</span> <span>for a school</span><span>,</span> <span>is very strict</span> <span>normalize the</span> <span>database correctly</span><span>,</span> <span>because</span> <span>so</span> <span>saving</span> <span>two columns</span> <span>(</span><span>id_provincia</span> <span>and</span> <span>id_municipio</span><span>)</span> <span>in table</span> <span>(</span><span>employee)</span></span></p>
<p>&nbsp;</p>
<p>i have 3 set_relation</p>
<pre class="_prettyXprint _linenums:0">
$crud-&gt;set_relation('id_municipio','municipio','desc_municipio');
$crud-&gt;set_relation('id_provincia','provincia','desc_provincia');
$crud-&gt;set_relation('id_consejo_popular','consejo_popular','desc_consejo_popular');

</pre>
<div id="gt-src-tools">
<div id="gt-src-tools-l">
<div id="gt-input-tool" style="display: inline-block;">
<div id="itamenu">&nbsp;</div>
</div>
</div>
</div>
<div class="almost_half_cell" id="gt-res-content">
<div dir="ltr" style="zoom:1"><span class="short_text" id="result_box" lang="en"><span class="hps">but I want</span> <span class="hps">to know</span> <span class="hps">if I can</span> <span class="hps">do something like</span></span>:</div>
</div>
<pre class="_prettyXprint _linenums:0">
$crud-&gt;set_relation('consejo_popular.id_municipio','municipio','desc_municipio');
</pre>
<p><span><span>I understand</span> <span>how it works</span> <span>Grocery</span> <span>CRUD</span><span>,</span> <span>but I want to</span> <span>see if I can</span> <span>change something</span><span>,</span> <span>create another</span> <span>extended model</span> <span>grocery_CRUD_Model</span> <span>or something</span> <span>to make</span> <span>operating the</span> <span>GC</span> <span>with my</span> <span>normalized database</span><span>.</span></span></p>
<p>&nbsp;</p>
<p><br />
&nbsp;</p>

kenshicu

kenshicu
  • profile picture
  • Member

Posted 20 March 2013 - 22:55 PM

Yes, I understand that, but as I need this for a school, is very strict normalize the database correctly, because so saving two columns (id_provincia and id_municipio) in table (employee)

i have 3 set_relation
 

$crud->set_relation('id_municipio','municipio','desc_municipio');
$crud->set_relation('id_provincia','provincia','desc_provincia');
$crud->set_relation('id_consejo_popular','consejo_popular','desc_consejo_popular');


but I want to know if I can do something like:
 

$crud->set_relation('consejo_popular.id_municipio','municipio','desc_municipio');


I understand how it works Grocery CRUD, but I want to see if I can change something, create another extended model grocery_CRUD_Model or something to make operating the GC with my normalized database.


vladbutterfly

vladbutterfly
  • profile picture
  • Member

Posted 28 April 2013 - 20:06 PM

Hi kenshicu

Any fixe for your issue bacause I have the same thx

 

kenshicu

kenshicu
  • profile picture
  • Member

Posted 29 April 2013 - 12:17 PM

if recently found a temporary "solution"

I removed:

$crud->set_relation('id_provincia','provincia','desc_provincia');
$crud->set_relation('id_municipio','municipio','desc_municipio');

And then added: (id_provincia, id_municipio) to display the selectbox to Add / Edit

$crud->fields('field1','field2','field3','id_provincia','id_municipio');

By adding (id_provincia, id_municipio) to form, fails to save because these fields do not exist in the database, then:
 

// CALL DELETE THE FORM FIELDS UNAVAILABLE
    $crud->callback_before_insert(array($this,'_callback_before'));
    $crud->callback_before_update(array($this,'_callback_before'));


And the relevant function
 

// REMOVE EXISTING FORM NO FIELDS
    function _callback_before($post_array)
    {
    unset( $post_array['id_provincia'] );
    unset( $post_array['id_municipio'] );
    return $post_array;
    }

Just need to use a:
 

$crud->callback_field ( 'id_provincia', array ( $this, '_callback_field_provincia' ) );
$crud->callback_field ( 'id_municipio', array ( $this, '_callback_field_municipio' ) );

to fill the added selectbox