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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

[solved] Adding an extra non-db field to query?


Go to End


2 Posts   1275 Views

Avatar
Sparrowhawk

Community Member, 33 Posts

17 July 2010 at 3:04am

Edited: 17/07/2010 8:16am

Hi,

I'd like a DataObject::get call to return what it normally does, plus another field with the same value for each row (I won't bore you with why)

I thought I could use the join parameter to create a cartesian result-set thus:

$results = DataObject::get('AcademicVideoPage', null, null, "INNER JOIN (SELECT $this->vpid AS `vpid`) AS `v`");

However, whenever I try to output $vpid to the template, nothing is inserted. All the normal AcdemicVideoPage fields are there though.

doing a var_dump on $results confirms that vpid is not there.

What exactly am I doing wrong here - the documentation seems to imply that I can do it this way, but I may be misreading/misunderstanding.

Many thanks for any help.

Version 2.3.3, OS X

Avatar
Sparrowhawk

Community Member, 33 Posts

17 July 2010 at 3:30am

Figured out why:

Because the join param does not force the get method and the method it then uses in turn to include the fields in the join as part of the returned field list.

OK, well, looks like it's manual SQL using SQLQuery then! :)