3341 Posts in 982 Topics by 703 members
|Go to End|
6 June 2009 at 4:41pm
DataObject::get('Page', "`ClassName` IN ('VideoPage', 'ArticlePage', 'EventPage', 'MusicPage') AND `FeaturedHomePage` = 1", 'Created DESC', null, $number);
Getting the error that the where clause is ambiguous. I understand that it is caused because each pagetype has the same field "FeaturedHomePage".
I'm trying to return only the 4 pagetypes wherever FeaturedHomePage is true.
How do I rewrite this?
8 June 2009 at 9:49am
Why don't you have "FeaturedHomePage" field on Page model instead of having this field on its subclasses?
8 June 2009 at 11:09am
The reason was that only those 4 pagetypes have the FeaturedHomePage field. I have more than 4 custom page types, so was trying to keep it clean and organized.
Is it better practice to add it to the page type and let every custom page type inherit it even when it's not needed?
Is there no other way to pull the data I want from the 4 custom page types with the FeaturedHomePage field set to true?
8 June 2009 at 11:35am
I see. Well, for me I would create new subclass of page type with FeaturedHomePage field and let these 'VideoPage', 'ArticlePage', 'EventPage', 'MusicPage' page types subclass the new page type.
Or you can pull in one page type at a time and combine them.
$featuredVideoPages= DataObject::get('VideoPage', "`FeaturedHomePage` = 1", 'Created DESC', null, $number);
$featuredArticlesPage= DataObject::get('ArticlePage', "`FeaturedHomePage` = 1", 'Created DESC', null, $number);
$featuredEventPages= DataObject::get('EventPage', "`FeaturedHomePage` = 1", 'Created DESC', null, $number);
$featuredMusicPages= DataObject::get('MusicPage', "`FeaturedHomePage` = 1", 'Created DESC', null, $number);
// combine them
Another way is you can use raw sql with UNION keyword.
8 June 2009 at 1:02pm
Thanks for the suggestions. I think I'll go with your former suggestion in your 2nd post. I'd prefer to stay away from raw sql and use the built in stuff and obviously the less queries the better.
Just wasn't sure if there was a way to rewrite it with one query like how I was going initially.
Is there a way to block page types from being created in the admin section? If I setup this new subclass of the page model for these 4 pages to inherit, it's going to show up in the admin which I don't really want since it won't be used per se. Would prefer to keep the options simple for the content editors using the admin.
Think this has been brought up before, but a quick search can't find anything.
8 June 2009 at 1:42pm
You might wanna open a ticket for this option (hide a page type in cms).
|Go to Top|