Hello,
I am not able to set relation n to n for my models. I know it has "has_many"' for relation one to many, but how can I manage relation n to n like grocery crud in codeigniter( example in grocery crud:$crud->set_relation_n_n('projects', 'fuel_site_projects_customers','fuel_site_customers', 'id', 'id', 'title','priority');).
Any suggestion would be appreciated.
Comments
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); require_once(FUEL_PATH.'models/base_module_model.php'); class Projects_model extends Base_module_model { // keys are model, which can be a key value pair with the key being the module and the value being the model, module (if not specified in model parameter), relationships_model, foreign_key, candidate_key public $has_many = array( 'customers' => 'customers_model' ); function __construct() { parent::__construct('projects'); // table name } }
Fuel automatically stores relationships in a fuel_relationships tables. Also have a look here: http://docs.getfuelcms.com/general/models#relationships
your comment's last line answered me that FUEL will automatically save the relationship in the fuel_relationships table without needing to setup a separate lookup table.
Do I have to set belongs to in Customers model or it is exactly the same as Projects model and both (Projects and Customers have has_many properties, or one of them has has_many and the other belong_to?
Thank you so much for your help
how to join this two table with relation n to n ?
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); require_once(FUEL_PATH.'models/base_module_model.php'); class Customers_model extends Base_module_model { // keys are model, which can be a key value pair with the key being the module and the value being the model, module (if not specified in model parameter), relationships_model, foreign_key, candidate_key public $belongs_to = array( 'locations' => 'locations' ); function __construct() { parent::__construct('customers'); // table name } }
https://codeigniter.com/user_guide/database/query_builder.html
For many to many relationships, FUEL uses the table fuel_relationships as a lookup table and can be joined using CodeIgniter's query building syntax. The blog_posts_model may be an example you can lookout (in particular the _common_query() method):
https://github.com/daylightstudio/FUEL-CMS-Blog-Module/blob/master/models/blog_posts_model.php
Additionally, depending on what you are wanting your returned data to including, you may not need to do this because the FUEL will automatically create magic methods and properties on a particular record that has a many to many relationship. More on that here:
http://docs.getfuelcms.com/general/models#relationships
I would like to contribute to Persian language of fuel CMS.
I have already done the translation, where shall I post it?
https://github.com/daylightstudio/FUEL-CMS-Languages
Working with Github is difficult for me.
So please check them and inform me if they are true.
I was not able to make a folder (Persian folder), I just created the specefic file there.