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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

Relation between member and guest(visitor)


Go to End


10 Posts   2579 Views

Avatar
Johnny9

Community Member, 35 Posts

13 April 2015 at 6:09pm

Edited: 13/04/2015 6:10pm

Hi, I want to have relation between member and guest(visitor).

I understand that member has many guests and guest has one member, but in this situation it don't save GuestID, just MemberID which page I visited.
So when I want to know who visited, I don't get that GuestID.

How to set relation between member and guest properly? Thanks for any help..

Avatar
Johnny9

Community Member, 35 Posts

13 April 2015 at 8:20pm

Edited: 13/04/2015 8:20pm

Should I just have relation like this in Guest.php:

private static $has_many = array(
"Member" => "Member",
"Guest" => "Member"
);

Just want to know if I do it right way?

Avatar
Pyromanik

Community Member, 419 Posts

13 April 2015 at 9:00pm

Your wording sounds very odd, in that guests don't normally have any objects associated with them, but I guess you're doing something I don't particularly understand.

To create a relation, you should define it on BOTH objects, just once for each.

visitor has_one member (defined in the visitor class)
member has_many guest (defined via a DataExtension applied to Member)

Relation help: http://iforce.co.nz/i/quv5meng.sv4.png
defining relations: http://doc.silverstripe.org/en/developer_guides/model/relations/
working with DataExtension: http://doc.silverstripe.org/en/developer_guides/model/extending_dataobjects/

Avatar
Johnny9

Community Member, 35 Posts

13 April 2015 at 10:48pm

Edited: 13/04/2015 10:53pm

I will try to explain.

Member.php code:

class MemberExtension extends DataExtension {
	...
	static $has_many = array(
              'Guests' => 'Guest'
	);
	...	
} 

And Guest.php
class Guest extends Dataobject {
	...
	static $has_one = array(
              'Member' => 'Member'
	);
	...	
} 

Let's say I visit other member profile and system automaticaly creates Guest record in database with that member ID. So that member has 1 guest.
But where to add my member ID as guest? Should I just have:
class Guest extends Dataobject {
	...
	static $has_one = array(
              'Member' => 'Member',
              'Guest' => 'Member'
	);
	...	
} 

And fill GuestID with my member ID?
Hope you understand :)

Avatar
Pyromanik

Community Member, 419 Posts

14 April 2015 at 1:24am

It sounds as if a Guest is a Member, and you're tracking who's viewing whom's page.

in which case Guest should also be a dataextension (probably in the same dataextension), and it also sounds as if the relationship should be many_many, as a guest can visit any number of members, not just one.

In which case it's more like:

private static $many_many = ['Guests'=>'Member'];
private static $belongs_many_many = ['Visited'=>'Member']

Am I right?

Avatar
Pyromanik

Community Member, 419 Posts

14 April 2015 at 5:06am

It is I who still does not understand you.
Here it would be best if you explained _what_ you're trying to achieve, not _how_ you're trying to achieve it.

Avatar
Johnny9

Community Member, 35 Posts

14 April 2015 at 5:15am

Edited: 14/04/2015 5:16am

Ok, let's say I have dating portal, I visit members profiles, they visit mine profile. So I want to track who visited my profile, return list of these members. Also, I want to get a list, which members I visited.
So I want to understand what relation should I use. Thanks for helpping :)

Avatar
Johnny9

Community Member, 35 Posts

15 April 2015 at 10:47pm

So, no help?

Go to Top