Hello there,
I'm new to Joomla programming and as you can imagine a bit confused.
I've got a background in C++/Java programming and some PHP (but really
not an expert). I've read the Joomla! Programming by Dexter&Landry
(great, but without simple, precise examples), some tutorials here and
there including part of the
http://docs.joomla.org/Developing_a_Model-View-Controller_Component/2.5.
I'm writing a first "test" component that works with specific tables
and do not use Joomla's (e.g. Categories). What I need to know is how
to do things correctly with related tables (one to one, one to many,
many to many) if I want to follow the Joomla MVC.
Specific problem : how to work (backend first, then frontend) on
tables with relationships ?
Here the basics :
Tables :
Name : OriginalTeam
Fields : id, name
Name : Team
Fields : id, name, idOriginalTeam, description
idOriginalTeam being of course one to one related to OriginalTeam.id
(without real constraint validation on the mysql side)
What I want to do is IMHO simple :
Backend :
1) show the list of Teams with Original Team name and not id => done,
quite easy, you just have to set the query in getOptions to do that
$query->select('
a.id,
a.name,
b.name AS
originalteam,a.description');
$query->from('#__avansisleague_team AS a,
#__avansisleague_originalteam AS b');
$query->where('a.idoriginalteam =
b.id');
and then store the options accordingly
foreach($teams as $team)
{
//echo ("<br/> in JFFOriginalTeam
- team id/name : " . $team->id."/".$team->name) ;
$options[] =
JHtml::_('select.option', $team->id, $team->name, $team->originalteam,
$team->description);
}
2) edit the Team and show instead of the idOriginalTeam a combobox
with the available names out of the database
3) save the Team with of course the correct idOriginalTeam and not the
OriginalTeam.name
Again, that's something quite easy, routine in any language/framework
I came across, and I could brute force it writing probably poor code
compared to what I could do using the Joomla framework correctly...
and the question is similar for one to many and many to many cases.
In other words, how do I modify e.g. the models/forms/team.xml, the
models/fields/team.php and so on to be able to do that ?
Certainly lies the answer somewhere but as far as I've read, any
example I saw in Joomla of e.g. one to one cases rely on the Joomla
categories and that's not what I want, as any component I later on
write might be completely separated from the joomla DB.
Thanks in advance for your help and greetings out of Switzerland