⚠ In case you've missed it we are migrating 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 forum is read-only and soon will be archived. ⚠


N to N Relation

set_relation set_relation_n_n

  • Please log in to reply
7 replies to this topic

#1 RSPeres

RSPeres

    Member

  • Members
  • PipPip
  • 12 posts

Posted 16 January 2013 - 01: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

Attached Thumbnails

  • Screen Shot 2013-01-16 at 11.57.17 AM.png


#2 goFrendiAsgard

goFrendiAsgard

    Advanced Member

  • Members
  • PipPipPip
  • 137 posts

Posted 20 January 2013 - 03: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

#3 Pascal

Pascal

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 22 February 2013 - 09: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???



#4 Pascal

Pascal

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 22 February 2013 - 09: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?



#5 goFrendiAsgard

goFrendiAsgard

    Advanced Member

  • Members
  • PipPipPip
  • 137 posts

Posted 23 February 2013 - 01:23 AM

Which mysql function???

My own custom function.
Something like CREATE FUNCTION function_name



#6 davidoster

davidoster

    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts

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!



#7 davidoster

davidoster

    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts

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!



#8 goFrendiAsgard

goFrendiAsgard

    Advanced Member

  • Members
  • PipPipPip
  • 137 posts

Posted 23 February 2013 - 06: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.







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users