Message from discussion
static Method Use
Date: Thu, 8 Nov 2012 11:18:06 -0800 (PST)
From: Eric Ponce <poncee...@gmail.com>
To: geddyjs@googlegroups.com
Message-Id: <bb794ece-0778-45ce-babd-152b55090347@googlegroups.com>
In-Reply-To: <CALvYELA0DCHjDWRooGFJc6XHxwpkEfc6xHLGHi8RwTbG5Yj90g@mail.gmail.com>
References: <defb4cbc-dab4-49ad-9375-c836888e60a2@googlegroups.com>
<CALvYELA0DCHjDWRooGFJc6XHxwpkEfc6xHLGHi8RwTbG5Yj90g@mail.gmail.com>
Subject: Re: [geddyjs:247] static Method Use
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_79_23943994.1352402287211"
------=_Part_79_23943994.1352402287211
Content-Type: multipart/alternative;
boundary="----=_Part_80_8411722.1352402287211"
------=_Part_80_8411722.1352402287211
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
thanks Matthew but your code give me an error:
Event.getFutureEvents =3D (callback) {=20
^
SyntaxError: Unexpected token {
:O i've tried to solve it but i can't...
El jueves, 8 de noviembre de 2012 19:46:46 UTC+1, Matthew Eernisse escribi=
=C3=B3:
>
> You can't just `return` from an asynchronous function. You'll have to=20
> use a callback, like this:=20
>
> Event.getFutureEvents =3D (callback) {=20
> var today =3D new Date();=20
> Event.all({when:{gt: today}},function(err,events){=20
> //"when" is the Event date=20
> if (err) { callback(err, null); }=20
> else {=20
> callback(null, events);=20
> }=20
> });=20
> };=20
>
> On Thu, Nov 8, 2012 at 3:29 AM, Eric Ponce <ponc...@gmail.com<javascript:=
>>=20
> wrote:=20
> > Hi!=20
> >=20
> > I have two models: Articles and Events=20
> > In the index function of Articles Controller, i've tried to do this:=20
> >=20
> > geddy.model.Article.all({},{sort: {createdAt:"desc"}},function(err,=20
> > articles) {=20
> > self.respond({params: params, articles: articles, events:=20
> > geddy.model.Event.getFutureEvents()});=20
> > });=20
> >=20
> > and in te Event Model=20
> >=20
> > Event.getFutureEvents =3D function () {=20
> > var today =3D new Date();=20
> > Event.all({when:{gt: today}},function(err,events){=20
> > //"when" is the Event date=20
> > return events;=20
> > });=20
> > }=20
> >=20
> > But in the controller I don't recibe anything.=20
> > If I put console.log(events) in the Event Model I can see all events.=
=20
> >=20
> > Can you help me?=20
> > Thanks! :D=20
> >=20
> > --=20
> > The official community discussion group.=20
> > website: geddyjs.org, source: https://github.com/mde/geddy, group:=20
> > https://groups.google.com/d/forum/geddyjs?hl=3Den=20
> >=20
> >=20
>
------=_Part_80_8411722.1352402287211
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
thanks Matthew but your code give me an error:<div><br></div><div><div styl=
e=3D"background-color: rgb(250, 250, 250); border: 1px solid rgb(187, 187, =
187); word-wrap: break-word; " class=3D"prettyprint"><code class=3D"prettyp=
rint"><div class=3D"subprettyprint"><font color=3D"#660066"><div class=3D"s=
ubprettyprint">Event.getFutureEvents =3D (callback) { </div><div class=
=3D"subprettyprint"> =
^</di=
v><div class=3D"subprettyprint">SyntaxError: Unexpected token {</div></font=
></div></code></div><br>:O i've tried to solve it but i can't...<br><br>El =
jueves, 8 de noviembre de 2012 19:46:46 UTC+1, Matthew Eernisse escribi=C3=
=B3:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex=
;border-left: 1px #ccc solid;padding-left: 1ex;">You can't just `return` fr=
om an asynchronous function. You'll have to
<br>use a callback, like this:
<br>
<br>Event.getFutureEvents =3D (callback) {
<br> var today =3D new Date(=
);
<br> Event.all({when:{gt: today}},function(err,e=
vents){
<br> //"when" is the Event date
<br> if (err) { callback(err, null=
); }
<br> else {
<br> callback(null, events)=
;
<br> }
<br> });
<br>};
<br>
<br>On Thu, Nov 8, 2012 at 3:29 AM, Eric Ponce <<a href=3D"javascript:" =
target=3D"_blank" gdf-obfuscated-mailto=3D"BXXD3DA2L1MJ">ponc...@gmail.com<=
/a>> wrote:
<br>> Hi!
<br>>
<br>> I have two models: Articles and Events
<br>> In the index function of Articles Controller, i've tried to do thi=
s:
<br>>
<br>> geddy.model.Article.all({},{<wbr>sort: {createdAt:"desc"}},functio=
n(<wbr>err,
<br>> articles) {
<br>> self.respond({params: params, articles: articles, ev=
ents:
<br>> geddy.model.Event.<wbr>getFutureEvents()});
<br>> });
<br>>
<br>> and in te Event Model
<br>>
<br>> Event.getFutureEvents =3D function () {
<br>> var today =3D new Date();
<br>> Event.all({when:{gt: today}},function(err,events){
<br>> //"when" is the Event da=
te
<br>> return events;
<br>> });
<br>> }
<br>>
<br>> But in the controller I don't recibe anything.
<br>> If I put console.log(events) in the Event Model I can see all even=
ts.
<br>>
<br>> Can you help me?
<br>> Thanks! :D
<br>>
<br>> --
<br>> The official community discussion group.
<br>> website: <a href=3D"http://geddyjs.org" target=3D"_blank">geddyjs.=
org</a>, source: <a href=3D"https://github.com/mde/geddy" target=3D"_blank"=
>https://github.com/mde/geddy</a>, group:
<br>> <a href=3D"https://groups.google.com/d/forum/geddyjs?hl=3Den" targ=
et=3D"_blank">https://groups.google.com/d/<wbr>forum/geddyjs?hl=3Den</a>
<br>>
<br>>
<br></blockquote></div>
------=_Part_80_8411722.1352402287211--
------=_Part_79_23943994.1352402287211--