⚠ 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. ⚠
Posted 12 August 2013 - 00:04 AM
Posted 12 August 2013 - 06:28 AM
Hello and welcome to the forums [member=paz_44].
If I were you I wouldn't use the id_product field from the product table.
I would have another field that would be an array('id_product'=>'description') where description is the combination of the fields you have mentioned.
This can be done by using the field_type function.
Now as a more general comment, you mentioned that this you're trying to do isn't supported by Grocery CRUD library.
Well let me rephrase this a bit and say, since this isn't supported from your tables' structure how can it be supported by GC library or any other library?
Explanation:
Since you have a table called product I suppose you would want to provide a nice combined user experience where in a single table he enters all the data about a single product including the fields trademark and model.
Saying this if you add two more fields on table product as name_model and name_trademark as set_relations then:
- you will not need a custom query to produce the desciption you want, e.g. product name, model and trademark
- on the table assignment you will be able to put a field that is a set_relation('description', 'product', '{name_proruct} {name_model} {name_trademark}');
Posted 13 August 2013 - 17:21 PM
Posted 14 August 2013 - 20:49 PM
Hello, thank you very much for answering.Regarding your response I commented that the reason for having the tables model and trademark is I want to avoid entering the same products not write trademark name differently or have errors in the model.So I was looking at how to create a new model with the query and to associate it with grocery crud.
Sorry, I can't understand what you mean here.
Posted 20 August 2013 - 17:45 PM
Hi paz_44,
you could add a new 'full_name' field on Products db table,
then you use the callback functions before Insert and before update for modified the value for this field.
Please read the documentation: http://www.grocerycrud.com/documentation/options_functions
In the callaback function you could:
$sql = "SELECT * FROM Trademark WHERE id_trademark = ?"; $trd = $this->db->query($sql, array($post['id_trademark']))->row(); $sql = "SELECT * FROM Model WHERE id_model = ?"; $mdl = $this->db->query($sql, array($post['id_model']))->row(); $tradename = $trd->name_trademark; $modelname = $mdl->name_model; $post['full_name'] = $post['nameProduct'] . ' ' .$tradename . ' ' . $modelname;
Then, on your controller method for 'assignment' db table,
$crud->set_relation('id_product', 'products', 'full_name');
Is Only an idea,
Thanks, regards.
Posted 21 August 2013 - 08:31 AM
Can you be more clear / specific as what is you want .. do you want to display the data from 3 tables in 1 or what exactly you looking into? IF you can explain it better / clearer.. we could help you better
Posted 15 September 2013 - 05:09 AM
Amit Shah
Thanks for helping!!!