Open source office hours 8/14 starting now!

85 views
Skip to first unread message

Ian Johnson

unread,
Aug 14, 2014, 12:01:02 PM8/14/14
to der...@googlegroups.com, sha...@googlegroups.com

Schrijver

unread,
Aug 18, 2014, 6:26:11 AM8/18/14
to der...@googlegroups.com, sha...@googlegroups.com
Hey—
maybe for the uninitiated, it would be good to have a sticky post explaining what the Open Source Office Hours are,
and when they usually take place?

If I understand correctly, they are a sort of collective Q&A moment?
Sounds really useful, though for now I’ve only seen these posts (‘starting now’) several days later ;)

Also, I seem to have trouble posting new topics to this discussion board. I’ve tried a few times to post a question about accessing ID’s with a dot in it.
Are they maybe moderated because the question is too basic?

Cheers, Thanks!

Eric

Op donderdag 14 augustus 2014 17:01:02 UTC+1 schreef Ian Johnson:

Schrijver

unread,
Aug 18, 2014, 7:19:32 AM8/18/14
to der...@googlegroups.com, sha...@googlegroups.com
So I’m just going to post my question here (sorry for the off topic!) because this seems to work.

My question is due to the lack of a findOne function.
I want to fetch one object of whom I know the id.
With this code it is working for me:

app.get('/w/:slug', function(page, model, _arg, next){
    var slug = _arg.slug;
    var text = model.at('documents.' + slug);
    text.subscribe(function(err) {
        model.ref('_page.text', text);
        page.render("write"); 
    });
});

However, know the ids will have dots in them, which breaks the standard way to fetch them.
So I query for the id.
However, now my code doesn’t work anymore because the result is an array.

app.get('/w/:slug', function(page, model, _arg, next){
    var slug = _arg.slug;
    var text = model.query('documents', {'_id' : slug});
    text.subscribe(function(err) {
        model.ref('_page.text', text);
        page.render("write"); 
    });
});

This code itself works, but I have to change all the templates to reference _page.text[0],
and the showdown component I was using stopped working.

So I love if I can still have a reference to just the one object like I had before.
What is the best way to achieve this?

Thanks!


Op maandag 18 augustus 2014 11:26:11 UTC+1 schreef Schrijver:

Schrijver

unread,
Aug 18, 2014, 7:36:03 AM8/18/14
to der...@googlegroups.com, sha...@googlegroups.com
Hmm, ok retrying to post—
I tried to reply before…
hm
My question is due to the lack of a findOne function.
I want to fetch one object of whom I know the id.
With this code it is working for me:

app.get('/w/:slug', function(page, model, _arg, next){
    var slug = _arg.slug;
    var text = model.at('documents.' + slug);
    text.subscribe(function(err) {
        model.ref('_page.text', text);
        page.render("write"); 
    });
});


However, know the ids will have dots in them, which breaks the standard way to fetch them.
So I query for the id.

app.get('/w/:slug', function(page, model, _arg, next){
    var slug = _arg.slug;
    var text = model.query('documents', {'_id' : slug});
    text.subscribe(function(err) {
        model.ref('_page.text', text);
        page.render("write"); 
    });
});

However, query gives an array.
Now I have to go into my template and change all the refererences to _page.text to _page.text[0]
Also the codemirror widget I was using isn’t working anymore.
So I would like to find a way to have page._text reference the object directly, not the array.
What is the best way to work around this?

Thanks!

Eric


Op maandag 18 augustus 2014 11:26:11 UTC+1 schreef Schrijver:
Hey—

Artur Zayats

unread,
Aug 18, 2014, 8:23:44 AM8/18/14
to der...@googlegroups.com, sha...@googlegroups.com
You can use model.ref('_page.text', 'documents.'+slug);

Artur Zayats

unread,
Aug 18, 2014, 8:27:06 AM8/18/14
to der...@googlegroups.com, sha...@googlegroups.com
Also instead of query you can use:


var text = model.at('documents.'+slug);

text.subscribe(function(){

  model.ref('_page.text', text);
  page.render("write"); 
});

or 

model.subscribe('documents.'+slug, function(){
  model.ref('_page.text', 'documents.'+slug);
  page.render("write"); 
});

Schrijver

unread,
Aug 18, 2014, 9:02:24 AM8/18/14
to der...@googlegroups.com, sha...@googlegroups.com
Hey, thanks for your reply!
The thing is, I can’t use derby’s path notation because I use dots in my id (the reason I tried to work-around using query)

Because if I pass a slug like: 'foo.html'
I get errors such as:

Error: Cannot subscribe to a path within a document: documents.foo.html


Op maandag 18 augustus 2014 13:27:06 UTC+1 schreef Artur Zayats:

Artur Zayats

unread,
Aug 18, 2014, 9:09:07 AM8/18/14
to der...@googlegroups.com, sha...@googlegroups.com
Ok. you of course can use the workaround with your query:

model.ref('_page.texts', text);
model.ref('_page.text', '_page.texts.0');

But I think it's not a good idea to use dots in your ids :(
Maybe you should preprocess ids before add/subscribe?

Artur Zayats

unread,
Aug 18, 2014, 9:11:22 AM8/18/14
to der...@googlegroups.com, sha...@googlegroups.com

Or, maybe just put slug at some other field (not in id)

Schrijver

unread,
Aug 18, 2014, 1:38:10 PM8/18/14
to der...@googlegroups.com, sha...@googlegroups.com
That work-around does it for me, great!

And I guess I’d also need to do that if the slug is on another field,
because finding on another field than _id means using the query method if I’m not mistaken.

Thanks, Cheers


Op maandag 18 augustus 2014 14:11:22 UTC+1 schreef Artur Zayats:

Ian Johnson

unread,
Aug 19, 2014, 2:41:50 PM8/19/14
to der...@googlegroups.com, sha...@googlegroups.com
This is a great point. I'll add it to the mailing list description!


--
You received this message because you are subscribed to the Google Groups "Derby" group.
To unsubscribe from this group and stop receiving emails from it, send an email to derbyjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ian Johnson

unread,
Aug 19, 2014, 7:06:35 PM8/19/14
to der...@googlegroups.com, sha...@googlegroups.com
I'm not sure why your message was pending on the meetup list, i let it thru even though it already sent? sorry for the weird google groups stuff.

i did update the description with a link to previous office hours and the current weekly time, thanks for the idea!


--
You received this message because you are subscribed to the Google Groups "Derby" group.
To unsubscribe from this group and stop receiving emails from it, send an email to derbyjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages