Jump to:

23551 Posts in 19348 Topics by 2891 members

General Questions

SilverStripe Forums » General Questions » [solved] Adding an extra non-db field to query?

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

Page: 1
Go to End
Author Topic: 704 Views
  • Sparrowhawk
    Avatar
    Community Member
    33 Posts

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

    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

  • Sparrowhawk
    Avatar
    Community Member
    33 Posts

    Re: [solved] Adding an extra non-db field to query? Link to this post

    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!

    704 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.