XF 2.2 Where to have a function?

Robert9

Well-known member
I have a class "Country";
when i view my countries, i can fetch leagues from this countries.

But where i put the code? To Country, because i fetch leagues for a country?

Or to class League, because we talk about Leagues?

Also:
when i view my leagues, i can fetch teams and matches

But where i put the code? To League, because i fetch teams and matches for Leagues?

Or to the classes Team and Match?

Also i could put all these "fetchFunctions" to a class Fetch.
 

If you want to go down from a single entity to another single entity or a set, you can use an entity relation for a quick access way. 1:1 relations can also be preloaded in the finder to avoid additional database queries.

If you're fetching a set for multiple items, use a finder. You can either write the query each time you need it and only go with the default finder or make your custom one with shortcuts in which you only have to pass a list of entities.
 
Thank you. Seems my wonderful English is nearly perfect to explain my needs.
So one more try:

class Country
  • view countries
  • add/edit/delete countries

class League
  • view leagues
  • add/edit/delete leagues

class Team
  • view teams
  • add/edit/delete teams


No i have added new functions:

-fetchLeagues
-fetchTeams
-featchMatches


My question is in which class i would add these new functions
Normally i would say:

class League
-fetchLeagues

class Team
-fetchTeams


but i have done it now like this:

class Country
-fetchLeagues - because i fetch the leagues for a country

class League
-fetchTeams - because i fetch the teams for a league

class Team
-featchMatches - because i fetch matches for a team
 
Back
Top Bottom