Jump to content

Joined fields not visible on Page object


Robin S
 Share

Recommended Posts

Hi @adrian,

I think this probably isn't a Tracy issue as such but I thought you might have some insight on it...

If I edit a field's settings (in this case the headline field) and set it to Autojoin then when I get a page whose template has that field then I can see the field value loaded on the Page object.

2022-01-17_112200.png.ff1518fa7c2e9ef127b8e05b9d55ea77.png

But if I don't set Autojoin in the field settings and instead I set the field to join for a specific find() operation then I don't see the field value loaded on the Page object. (I'm using $pages->get() here but I think it is the same behind the scenes and I also tried $pages->find() and found the same issue).

2022-01-17_112621.png.ff46f4d4fa5782619b7fa4bf2a3bd3c0.png

Or the older way:

2022-01-17_112723.png.9ab326afb4a96263e19278cd1904b601.png

If I request the field value before I dump the Page object then it is loaded.

2022-01-17_112901.png.3eeed3b5b7e4eb7f5691e5ac7ab29487.png

I'm puzzled about why this is. Surely if the field value is joined during the find() then it must be stored somewhere on the Page object? Do you know if PW is storing these joined values somewhere that is invisible to Tracy? Or is this maybe a sign that there's a core bug and the joined fields are not actually being preloaded as expected?

  • Like 1
Link to comment
Share on other sites

Hi @Robin S - not completely sure, but here's a little more insight:

image.png.7dd96c962f2e6289eb8a8941ec5445a8.png

This version shows that it is theoretically joining the "summary" field, and if I look at the Selector Queries section of the Debug Mode panel, I see:

image.png.780ac2900e517fb1afa3c62b934ff4cd.png

which shows that it is being joined as expected.

Now if I do this same find operation in a template file, I get:

image.png.dbfc9bab48b827c045a5f09c9e479126.png

Sorry for the rambling, but I am posting as I try new things :) I've noticed that if I run this via the Tracy console it actually does work as expected depending on what page you are on. It seems like it works anywhere on the frontend and anywhere on the backend, except when editing a page (which is what I was doing for my first test above). For example, you can see it working when viewing the page tree. Actually, it even seems to work when editing some page, but not all.

image.png.946b1cb68d637aec0928ce68d86c6f3b.png

 

What page / view are you on when testing and does that impact what you see?

  • Like 1
Link to comment
Share on other sites

10 minutes ago, adrian said:

I've noticed that if I run this via the Tracy console it actually does work as expected depending on what page you are on. It seems like it works anywhere on the frontend and anywhere on the backend, except when editing a page (which is what I was doing for my first test above).

You nailed it! I was trying that code from the Tracy Console while viewing the page in Page Edit, and so must have been getting the cached version of the page that was already loaded. If I use the Console on a different page or preceed the code with $pages->uncacheAll() then it works as expected. Thanks!

  • Like 1
Link to comment
Share on other sites

Turns out with your "get" version, you can also use getFresh() and it will work. 

Although I actually think this is kind of a bug in the Console panel. What do you think about me replacing line 73 of CodeProcessor.php with:

$setVars = '$page = $pages->get('.$page->id.'); $pages->uncacheAll();';

 

  • Like 1
Link to comment
Share on other sites

58 minutes ago, adrian said:

What do you think about me replacing line 73 of CodeProcessor.php with:

$setVars = '$page = $pages->get('.$page->id.'); $pages->uncacheAll();';

Sounds good to me, because although the cached pages are expected when you know how PW goes to the cache first before loading pages from the DB this might not be common knowledge and the expectation is probably that the Console is a "blank slate".

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...