Backbone Parse pointer query - join table - backbone.js

Firstly I had gone through this Parse join query using Javascript pointer and its not working as they stated.
I would like to state what I want to achieve
Child Table
pointer (parent) -> Parent Table
Parent Table
var query = new Parse.Query(ParentModel);
query.include('parent');
query.fetch({
success: function(result){
console.log(result.get('parent'));
}
})
I'm getting undefined for this.
First I would like to know whether this is achievable? Because I found that only 1 post stated this is possible and other is showing the other way round..
I have been stuck for few days for this. Please help out.
Thanks.

Related

Is there a way to update nested objects in firestore without overwriting other values?

I'm new to web development, so I'm extremely sorry if the question is rife with inaccuracies.
My firestore database is composed like so:
Is there a way in which I could update bookname under a specific card (for instance card1)
Right now my approach is to use the following function:
But when I execute the IssueBook() function, I get an error shown on the console:
As far as I can see, the card1 field does have two fields within which can be updated so what does the console message imply?
Thank you in advance!
It looks like you have a nested field under LibCard. To update a field in a nested object you can use dot notation:
updateDoc(doc(db, "users", docid), {
"LibCard.card1.bookname": "Coraline"
});

(mongo) Arrays of ids : how should I do it?

today I finished the functional part of my website, so I went into the secure-my-app part of development. I want to give to users only the content they are related to, so, to my teachers ( = a user with user.role == "teacher"), I only want to give them access to a given assignment if their _id is in the assignment.teachersList array of _ids. I want to make this verification in the publish so i MUST get a cursor in the end of the query.
After looking at the OFFICIAL documentation of mongo , it seems like doing what I want should be as simple as :
// in a publish
Assignements.find({ teachersList: this.userId });
However, this always returns me false. First, being afraid of a this context problem, I tried something like :
// in a publish
let self = this;
Assignements.find({ teachersList: self.userId });
and it's not better, I still get nothing. I tried to use Cursor.map() and put my condition there, but as map doesnt return a cursor, I get the data but it's not working either since we are in a publish.
It's written in the doc that the first try I made should work, so no doubts I'm making something wrong, but what .. ?
Right now i'm starting to wonder if the problem comes from the fact that it's an array of _ids. Right now, it's only an array of Strings. And it seems that this.userId in a method only returns a String.... But maybe i'm wrong and I should use Meteor.Mongo.ObjectId(the_string_id) objects instead?
Alright that's it ! Please, if you have any idea why such an easy query doesnt work, tell me ! Thanks :)
teachersList is an array, and not an id. You are trying to find an document with an id that has the value of an array... not going to work...
I usually use this pattern on all private owner collections: add an onInsert event to my collection and then add the user as ownerId to the document being inserted. Then, when it comes to publish, I publish all documents with the ownerId of the user. Clean and simple, no roles even needed...
If, however you decide not to use the pattern above...
From MongoDB:
db.inventory.find( { tags: { $in: [ /^be/, /^st/ ] } } )
This query selects all documents in the inventory collection where the tags field holds an array that contains at least one element that starts with either be or st.
In Meteor your query might look something like:
Assignments.find({ownerId: { $in: teachersList}});

paginate an union in Cakephp 3

I'm trying to paginate a union in cakephp 3. I have already found and read How do you modify a UNION query in CakePHP 3?, but am probably too new to cakephp to understand properly what is meant by "use a custom finder". I have read the relevant section in the cakephp book, but still fail to see how this helps to apply the epilog() to the query. Maybe someone could show a complete example?
I have two models Customers and Suppliers. I am trying to builds a search function that returns matching entries from both models, including pagination and sorting.
public function index($q=null) {
$this->loadmodel('Suppliers');
$this->loadmodel('Customers');
$customers=$this->Customers->find('all')->select(['type'=>"'Customers'",'id'=>'id','name'=>'name','phone'=>'phone'])
->where(['name like'=>'%'.$q.'%']);
$suppliers=$this->Suppliers->find('all')->select(['type'=>"'Suppliers'",'id'=>'id','name'=>'name','phone'=>'phone'])
->where(['name like'=>'%'.$q.'%']);
$customers->union($suppliers);
$results=$this->paginate($customers);
$this->set(compact(['q','results']));
}
As detailed in How do you modify a UNION query in CakePHP 3?, this results in the order,limit and offset only being applied to the first select.
Removing the paginate() and applying order,limit and offset manually via epilog() works, but than I'd have to recreate the whole pagination mechanism in my code. While this is my current plan in case I can't find a better solution, I don't believe this would be the right way to do it.
Could someone (#PhantomWatson, #ndm) show an example, how the suggested custom finder can solve this?

ExtJs select component by id starting with a string

i need to create a component dynamically by a button click. My restrictions are:
It's going to has an Id starts with a fixed string like 'myComp_' and followed by a random number
At any time there will be only one component that has an id starts with 'myComp_xxx'
So before creating the component i have to check if there's any created before and remove it... My problem starts here. Ext.getCmp() wants the specific id. But i only have that fixed string : myComp_...
Is there any way to get the component created before???
Thanks in advance and sorry about my English.
For ExtJs 4.X use Ext.ComponentQuery.query('*[id^=myComp_xxx]');
For ExtJs 3.X you can either use the following
var el = Ext.query('*[id^=myComp_xxx]');
var cmp = Ext.getCmp(el.id);
Or (this one i haven't tried personally, but i think it should work) if the component is a child of a component that you can access, then:
var el = parentComp.find("action","btn");
and set a property called action : btn in the button config.
I think what you are looking for is DomQuery.
Ex:
Ext.query("*[id^=myComp_xxx]")
You need to use this: Ext.getCmp(id)
Ext.getCmp("myComp_xxx");
Sounds like you should be using the normal component query stuff - in general it is not a good idea to use id. You can query by xtype and by itemId (which you can assign manually).
The following
Ext.ComponentQuery.query('grid form');
would find all things with xtype grid that have forms inside them somewhere.
Ext.ComponentQuery.query('grid #okButton');
whereas the # here is saying look for grids that have something with itemId 'okButton' in them.
You can nest this to whatever level you need and use other operators to be more specific and as someone else has rightly pointed out you can use up and down on components to do this relative to the current component. Its worth noting that rather than getting an array back with all the results you just get the first one when you use up and down.
See the documentation for more information this.
Also see point 6 on this list of bad practices to avoid for more of the why
Another alternative if you know 'where' your component is going to be created is to use the up()/down() methods.
E.g. if you have a button and want to get the form it's contained within inside a click handler you can do something like this:
function myClickHandler(btn) {
var form = btn.up('form');
//do something with form
}

How to populate a Backbone.js collection's _byId array so that I can use `get` on it?

I have a collection, and the collection.models returns an array of models. However, when I call collection.get(someId) (and this id is the id of the model that is in the collection.models array), I get undefined. Looking at collection._byId, it looks like an empty object.
How do I properly populate _byId, so that I can use get? Or perhaps I'm doing something wrong when initializing my collection, which is why _byId is empty.
I'm a little late, but hopefully this is still useful to some other people.
Collection._byId is just a normal js hash object. There's really nothing fancy about it. If you want Collection.get to work, just add all the models into the _byId hash.
Inside the collection's scope:
var someId = '123'; // any id will do
this._byId[someId] = someModel; // someModel.id = '123'
console.log(!!this.get(someId)); // should return true
Since I'm using this with Rails, the default json generated by Rails doesn't work well with Backbone. I don't know why I didn't see it while trying to learn Backbone. Anyway, you could either:
Change the way Rails generates its JSON
Change the way your Backbone app reads the JSON.
Sounds like the OP had a slightly different problem, but I experienced a similar issue and thought I'd post what worked for me.
Like the original issue, collection.models contained the right model, but in my case, the _byId hash contained a cid version of the model that wasn't empty. Nevertheless, _byId didn't contain a model with normal id (there's usually two version - an id one and a cid one), so I wasn't able to use collection.get(id) to retrieve it. My problem became a bit clearer when I read up about cid. From the docs:
Client ids are handy when the model has not yet been saved to the server, and does not yet have its eventual true id, but already needs to be visible in the UI.
I didn't think it was a problem with waiting for the server as my cid model and the collection.model had the correct ids. However passing in { wait : true } as an option in collection.create fixed this issue for me.

Resources