This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

svencieslok24308
svencieslok24308

Hello together, I already think about me that I'm stupid but i have a problem in my thinking.

I want to display a form where its possible to select Team A, give Team A the Score A, then select Team B and give them the Score B. I created the following tables:

  • plugin\teams
  • plugin\matches
  • plugin\matches teams <-- pivot table with team_a_id, team_b_id, match_id

In the Match Form I have to add relations, right? for both:

  • Field name: team In the relations tab
  • Name column: team_name

How does it select team a in the database? I only worked with 1:1 relations in october. I'm really confused atm. I hope that I could explain my challenge clearly :D

In best regards Sven

svencieslok24308
svencieslok24308

Small EDIT: I talked to a collegue... It should be a 1:n relationship, because 1 Team can have n Games. My mainproblem is anyways there. How can I use multible Teams in the Table "matches"? In the match.php i have to resolve two teams which should be different from each other.

I thought about creating something like a "hometeam" table and a "awayteam" table but this would be very "boring"

In best regards Sven

svencieslok24308
svencieslok24308

Major update: I finally found out my solution. Like mentioned I used One To Many relations

public $belongsTo = [
    'team_a' => ['xxx\xxx\Models\Team', 'name' => 'id', 'otherKey' => 'id'],
    'team_b' => ['xxx\xxx\Models\Team', 'name' => 'id', 'otherKey' => 'id']
];

I only have still a last minor problem: I want to display the results of the matches in the backend table. For this I did the relation

  team_a_id:
        label: 'xxx.xxx::lang.hometeam'
        type: text
        searchable: true
        select: name
        relation: team
    team_b_id:
        label: 'xxx.xxx::lang.away_team'
        type: text
        searchable: true
        select: name
        relation: team

But this solution is not working like expected. I had to add a third relation:

'team' => ['SvenC\ComMgmt\Models\Team', 'key' => 'id', 'otherKey' => 'id']
 

which seemed to work but with every added match it looked for a next team_id, which didn't brought my wished results. Do you guys have an idea?

in best regards Sven

Last updated

svencieslok24308
svencieslok24308

Final Update. I got it. This config works.

team_a_id:
        label: 'xxx.xxx::lang.hometeam'
        type: text
        searchable: true
        select: name
        relation: team_a
    team_b_id:
        label: 'xxx.xxx::lang.away_team'
        type: text
        searchable: true
        select: name
        relation: team_b

Last updated

svencieslok24308
svencieslok24308

Hey guys, I'm trying to implement this list now in the Frontend. But I'm stuck with the inverse relation.

{{ record.team_a_id }}
{{ record.score_a }}

Using this twigs gives me the right Team IDs for the teams table but i dont know how to enter this table. I need the element "teams.path_picture" and "teams.name". The SQL Statement should something like this:

Select teams.name teams.path_picture from teams where team.id = xxx

In best regards Sven

svencieslok24308
svencieslok24308

Okay I tried a little bit around and installed the "Debugbar plugin".

{% for team in record.team_a %}
  

{{ team.name }} {% endfor %}

The PHP Part works I guess. In the debugbar it searches the right SQL Query. But my problem is that it doesnt renders the name or picture path in it.

In best regards Sven

Last updated

1-6 of 6

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.