XF 2.0 defaultWith

Snog

Well-known member
Now I haven't done any research on this so it may be that people will need to forgive a stupid question. ;)

Why doesn't including a defaultWith in the user entity work across all pages, threads, posts?

I defined a defaultWith for some user statistics, but I have to include them in a few different areas with something like this..
Code:
$structure->defaultWith[] = 'User.SnogStats';

Again, without any research I would think the defaultWith in the user entity itself would include it everywhere automatically.
 
I've had a wee search through the code, and it seems like defaultWith is included when the Finder is instantiated via \XF::em()->getFinder($shortName)

I haven't been able to find any instance of Finder calls not calling that function. Can you elaborate on where you're not seeing this included? :)


Fillip
 
Specifically I have to include the User.SnogStats in the thread, post and conversation message entities for them to be included.

I'm not in front of my development system to search through the code, so I just thought I'd ask.

Sitting here thinking about it, it seemed odd to me that I'd have to do the include in other entities.
 
Last edited:
Do you have to do that include for every time those entities are used, or just in certain cases? If there's a bug somewhere, we might need to narrow it down before we can report it :)

I'm thinking, if you instantiated the thread entity yourself in a blank controller with a hardcoded thread_id, is it still missing? Similar for post and ConvMess.

That is of course assuming the devs haven't chimed in by the time you're back :D


Fillip
 
The general object is to include some stats in the extra user info block and the member card. So, any time a thread or post is shown it has to be included or they don't get included for all of the posts in a thread/conversation.

It drove me nuts why I was getting extra database calls while working on the add-on yesterday (to the tune of the number of users displayed (or close to it) on the page). The only way I could avoid them was to include the User.SnogStats in the thread, post and conversation message entities.
 
OK, I ran downstairs to my office to take a closer look at it.

I ran a finder on a specific thread with 'User' included in the finder and there are no default relations included with the returned user relation.
Code:
$info = $this->finder('XF:Thread')->with('User')->where('thread_id', 2377)->fetchOne();
print_r($info);

If I include the User.SnogStats, they are included.
Code:
$info = $this->finder('XF:Thread')->with('User')->with('User.SnogStats')->where('thread_id', 2377)->fetchOne();
print_r($info);

This is despite the defaultWith being defined in the User entity..
Code:
$structure->defaultWith[] = 'SnogStats';

On that note, it's Sunday... back to my regularly scheduled day of relaxation. :D
 
As was implied in the first reply, defaultWith only applies when you are fetching that content type as the "root" type. You would need to explicitly request it in other scenarios if relevant.
 
As was implied in the first reply, defaultWith only applies when you are fetching that content type as the "root" type. You would need to explicitly request it in other scenarios if relevant.
Well, then at least I know I'm not doing anything wrong the way I'm doing it. :)

It was just the "thought" of defaultWith meaning something more than it really does.
 
Top Bottom