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.

General Questions /

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

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

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


Reply


2 Posts   769 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! :)