Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

How to get the name corresponding to ID from other table?

Go to End

4 Posts   1167 Views


Community Member, 59 Posts

20 August 2011 at 8:04am


I have a table which contains only ID's from other tables and some additional data. Now I read this table, and I find a record, for instance

1, 10, 13
2, 15, 26

Now this is found using DataObject::get('CallerName'); inside the SomePage_Controller class

Offcourse I want to display in my templatefile not these rows, but the corresponding names which are stored in other tables (for instance Member, Articles, ....). How can I achieve this? just can't solve this at the moment.

Thanks for you help,


Forum Moderator, 1899 Posts

20 August 2011 at 8:44am

Hi Maurice,

something like this...

<% control CallerName %>

   has_one member - 

   has_many Articles - 
   <% control Articles %>
   <% end control %>

<% end control %>

more information in the tutorials and in the documentation about templates.



Community Member, 59 Posts

20 August 2011 at 10:11pm

Thanks for your help, however I still do not get it working. Maybe I am referencing wrong. I will give some more details of the situation at hand:


class Profile extends Page {

class Profile_Controller extends Page_Controller {
function CurrentSubscriptions() {
	// s11s = s ubscription s
	$cMember = Member::currentUserID();
	$s11s = DataObject::get("DanceCouples","PartnerAID = {$cMember} OR PartnerBID = {$cMember}");
	return $s11s;


Than I have the following code that creates the Model for the couples of persons:

class DanceCouples extends DataObject {
    static $db = array(
	'DansNiveau' => "Int"

    // Een lid kan meerdere koppels vormen
    static $has_one = array(
	'PartnerA' => 'DanceMemberInfo',
	'PartnerB' => 'DanceMemberInfo'

And the following Model for 'DanceMemberInfo':

class DanceMemberInfo extends Member {
    static $db = array(
	'Voorletters' => 'Varchar',
	'Geslacht' => "Enum('m,v')",
	'Adres' => 'Varchar',
	'Postcode' => 'Varchar',
	'Plaats' => 'Varchar',
	'Telefoon' => 'Varchar',
	'XtraCardNr' => 'Varchar'

    // Meerdere dansniveaus per lid toegestaan
    static $has_many = array(
	'DanceCouples' => 'DanceCouples',

The IDs which 'DansNiveau' refers to are created here:

class DanceCourses extends DataObject {
    static $db = array(
	'Name' => 'Varchar'

Is this a proper way of creating a model, so I can read all data to the template? How can I reference to it? I tried using the advanced-template reference of SS, but it did not help for me. Could you maybe give some suggestions?

Thanks a lot!

Ryan M.

Community Member, 309 Posts

21 August 2011 at 7:58am

I think you forgot to add a has_one or has_many relationship from DanceCouples to DanceCourses.