MarkE Posted January 12, 2023 Share Posted January 12, 2023 Having used PW for a few years now, I feel that this is a really basic question about something that ought to be obvious to me! So I'm prepared to say 'doh!' If I get a page object via the $page API (or page() or $pages or whatever) it doesn't always seem to have the fields fully populated. For example, here is the 'Field List & Values' display (partial) for a page 'gallery-of-apples', it has 5 fields: If I call $page and dump it, all I get is the title field, but by getting the fields via getFields() and setting them, I get the complete picture - see Tracy console image below: What is going on here? Why don't I get all the fields and values with $page? Link to comment Share on other sites More sharing options...
Robin S Posted January 12, 2023 Share Posted January 12, 2023 Field values for a page are loaded from the database on demand (i.e. as you request them) unless you have set them to be "autojoined": 2 Link to comment Share on other sites More sharing options...
MarkE Posted January 12, 2023 Author Share Posted January 12, 2023 Thanks @Robin S . Sort of ‘doh’ as I had heard of autojoin, but never used it or looked into it. That post explains everything, although I wonder if some fuller documentation in the API for $page might be helpful. I guess using autojoin is more efficient than getting the page then using getFields(). Link to comment Share on other sites More sharing options...
Robin S Posted January 12, 2023 Share Posted January 12, 2023 @MarkE, besides the autojoin setting in admin that's mentioned in Ryan's post, you can also set autojoin programmatically when you get one or multiple pages. For multiple pages ("find") see the blog post: https://processwire.com/blog/posts/find-faster-and-more-efficiently/ And if you only want a single page ("get") then you can use "joinFields" in the $options argument, e.g. Edit: it seems you can use the "field=" syntax described in the blog post with $pages->get() and $pages->findOne() too... 3 Link to comment Share on other sites More sharing options...
MarkE Posted January 13, 2023 Author Share Posted January 13, 2023 Thanks for all the tips, @Robin S. However one of the fields I need is a repeater matrix and that doesn't seem to support autojoin. Also, while I could get autojoin to work (for other fields) via the field settings, I couldn't replicate your example in my system - none of the requested ('autojoinable') fields were joined. I am on PW 3.0.206. findRaw() works as documented and gets all the fields and may be usable for my purposes, but that doesn't feel like the right answer. It seems like findJoin might be a bit buggy - I'm not sure @adrian's issue has been resolved. But it may be something strange in my set up. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now