⚠ 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

N to N Relation



RSPeres

RSPeres
  • profile picture
  • Member

Posted 16 January 2013 - 13:57 PM

Hi,

Is it possible to use this kind of query using set_relation_n_n? And populate the combos??




SELECT
c.cidade_id, c.cidade_nome, r.regiao_id, r.regiao_nome, e.estado_id, e.estado_sigla
FROM
tbl_area_atuacao a
INNER JOIN
tbl_cidades c
ON
c.cidade_id = a.cidade_id
INNER join
tbl_estados e
on
e.estado_id = c.estado_id
inner join
tbl_regioes r
on
r.regiao_id = e.regiao_id
where
a.atuacao_id = 1


The combo sequence will be tbl_regioes->tbl_estados->tbl_cidades

Thank's in advance

goFrendiAsgard

goFrendiAsgard
  • profile picture
  • Member

Posted 20 January 2013 - 15:48 PM

I've once do something similar by using MySQL function.
I use the function name as


$crud->set_relation('field_name', 'relation_table_name',
'{mysql_function(one_of_relation_field_name)}');

I hope it will also work for set_relation_n_n

Pascal

Pascal
  • profile picture
  • Member

Posted 22 February 2013 - 21:42 PM

I've once do something similar by using MySQL function.
I use the function name as
 

$crud->set_relation('field_name', 'relation_table_name', 
'{mysql_function(one_of_relation_field_name)}');
I hope it will also work for set_relation_n_n

Which mysql function???


Pascal

Pascal
  • profile picture
  • Member

Posted 22 February 2013 - 21:43 PM

Hi,

Is it possible to use this kind of query using set_relation_n_n? And populate the combos??

 


SELECT
c.cidade_id, c.cidade_nome, r.regiao_id, r.regiao_nome, e.estado_id, e.estado_sigla
FROM
tbl_area_atuacao a
INNER JOIN
tbl_cidades c
ON
c.cidade_id = a.cidade_id
INNER join
tbl_estados e
on
e.estado_id = c.estado_id
inner join
tbl_regioes r
on
r.regiao_id = e.regiao_id
where
a.atuacao_id = 1

The combo sequence will be tbl_regioes->tbl_estados->tbl_cidades

Thank's in advance

Hi did you find an answer to that problem?


goFrendiAsgard

goFrendiAsgard
  • profile picture
  • Member

Posted 23 February 2013 - 01:23 AM

Which mysql function???

My own custom function.
Something like CREATE FUNCTION function_name


davidoster

davidoster
  • profile picture
  • Member

Posted 23 February 2013 - 09:20 AM

At difficult cases I don't use the set_relation functions at all. I prefer to use my own model (via set_model) and then use the field_type to pass the values I want to the field!


davidoster

davidoster
  • profile picture
  • Member

Posted 23 February 2013 - 09:22 AM

My own custom function.
Something like CREATE FUNCTION function_name

 

Good idea but if I need to change it? I would need every time to go back to MySQL or end up with different MySQL functions that are not that easy to maintain.

So I prefer to program my own model and apply from there any level of complexity is needed to my data handling!


goFrendiAsgard

goFrendiAsgard
  • profile picture
  • Member

Posted 23 February 2013 - 18:16 PM

Good idea but if I need to change it? I would need every time to go back to MySQL or end up with different MySQL functions that are not that easy to maintain.

So I prefer to program my own model and apply from there any level of complexity is needed to my data handling!

Using model is actually better and easier to manage.