Forums

relation in db read action

teldrive 23 Mar, 2015
I am trying to use new feature "relation" in db read action
for example i am trying to get the usergroups associated to one user

model1= joom related to db jos_user
model2= group related to db jos_user_usergroup_map

in relation I have set:
type= hasmany
foreing key= user_id

b]in basic I have set:[/b]
<?php
$user="my username";
 return array('joom.username'=>$user,'group.user_id'=>'joom.id');
 ?>


did i miss anything?, can i do this with this feature?
Max_admin 02 Apr, 2015
Hi Teldrive,

Please try the conditions as below:

return array('joom.username'=>$user);


You can also use a "debugger" action under the "db read" to check the executed SQL.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 03 Apr, 2015
Hi Teldrive,

There is a Joomla! method for this
<?php
$user = JFactory::getUser();
$groups = $user->getAuthorisedGroups();
?>
or, for a user other than the current one
<?php
$user = JFactory::getUser($user_id);
$groups = $user->getAuthorisedGroups();
?>

Bob
teldrive 03 Apr, 2015
Thanks Bob, Max
the issue is to understand relation-option in db-read,i have used it in CC with models and I have found it very usefull . Now I am trying to understand how to use it in CF
The databases jos_user and jos_user_usergroup_map are just one simple example to try to understand it
joom.user_id=group.user_id is the related key between both databases but i couldn't get any values of second database that gets the condition
<?php
$user="my username";
return array('joom.username'=>$user);
?>

joom.user_id=group.user_id

How could i get group.group_id records?
Max_admin 17 Apr, 2015
Hi Teldrive,

Apologies for the delay.

There is a misunderstanding here I think, the main table is the one defined in the "db read" main area, and the relation is to this table, so if your table is set to jos_user and the relation table is the groups one then it should be easy.

Where do you have the "joom.user_id=group.user_id" ?

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
teldrive 18 Apr, 2015
Hi Max, that is the issue, and this is only an example to try to understand how it Works this new feature, i think i can simplify many forms;-)
it seems to me that one field is missing on this relation table section, I miss some field(as in cc is called "join conditions" ) where i can define relation between tables fields 😲 Please let me know if not necessary how to say that i need to locate all the(hasmany) group.group_id that match joom.user_id=group.user_id
Max_admin 20 Apr, 2015
Hi Teldrive,

I agree that a join conditions would be helpful but the foreign key field should be enough in this particular case, since you are using the primary key of the main table anyway.

Please send me as message using the "contact us" form to get a patch to test the Join Conditions in db read once I add it.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.