SPOD orderBy : something

56 views
Skip to first unread message

theRemix

unread,
Dec 7, 2013, 9:21:51 PM12/7/13
to haxe...@googlegroups.com
What is the recommended or documented way to have spod macros evaluate conditional options for orderBy ?

non-working example:
var results = manager.search(
  { pk_id : id },
  { orderBy : (
    if(true){
      -created_at;
    }else{
      created_at;
    }
  )}
);

here's another shot at it that of course doesn't work, though it should help me communicate what i want to do.
var opts = { orderBy : null };
if(true){
  opts.orderBy = -created_at;
}else{
  opts.orderBy = created_at;
}

var results = manager.search(
  { pk_id : id },
  { orderBy : opts}
);


postite

unread,
Dec 8, 2013, 10:07:21 AM12/8/13
to haxe...@googlegroups.com
doesn't orderby require an array ?


--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/groups/opt_out.

Sam MacPherson

unread,
Dec 8, 2013, 11:23:08 AM12/8/13
to haxe...@googlegroups.com
orderBy can take a identifier as well. You only need an array if you are doing secondary/tertiary/etc sorts.

Michel Romecki

unread,
Dec 8, 2013, 12:47:30 PM12/8/13
to Haxe ML
Hi,
I don't know if there is another way to achieve that :
var results = if ( true ) manager.search( { pk_id : id }, { orderBy : created_at } ); else manager.search( { pk_id : id }, { orderBy : -created_at } );


2013/12/8 Sam MacPherson <xyl...@gmail.com>

theRemix

unread,
Dec 8, 2013, 3:35:01 PM12/8/13
to haxe...@googlegroups.com
i was hoping that wasn't the case. it can get ugly very fast with just a few more conditions and cases.
it looks like it might be a limitation in the macro system, which i can live with for now.

Nicolas Cannasse

unread,
Dec 8, 2013, 4:05:51 PM12/8/13
to haxe...@googlegroups.com
Le 08/12/2013 21:35, theRemix a �crit :
> i was hoping that wasn't the case. it can get ugly very fast with just a
> few more conditions and cases.
> it looks like it might be a limitation in the macro system, which i can
> live with for now.

orderBy is meant to be statically typed, so no arbitrary runtime
expression is allowed atm.

Best,
Nicolas
Reply all
Reply to author
Forward
0 new messages