Cannot get relationships working with ember data - ember-data

I am using ember-data with RESTAdapter.
I have a module for Tours:
DS.Model.extend({
title: DS.attr('string'),
trips: DS.hasMany('trip')
});
this is populated with REST json:
[{
id: 132,
title: 'Tour title',
},...]
and a module for Trips:
DS.Model.extend({
tour: DS.belongsTo('tour'),
startDate: DS.attr('date')
});
this is populated with REST json:
{
id: 12345,
tour_id: 132,
startDate: '2013-01-01',
}
I would like so that that when using trip model I could call trip.tour.title to get a title of the tour. And respectively I could make tour.trips to get a list of all trips for the tour.
But somehow this is not working any relationships usage don't even trigger an ajax request. So I wonder why? All the properties are mapped correctly, but not relationships.
Please advice.

Seems like it was an old version of this libs, this is not relevant anymore.

Related

How do I get Watch Mode with Sanity.io and Gatsby to refresh content when referenced documents are edited in the CMS / Studio?

I'm using Sanity.io, GatsbyJS 3.x
Watch mode works great when you update content in the CMS, except for when the content you edit is part of a referenced schema of type 'document'.
Put another way, changes made to a document referenced by another document will not re-render the page despite having watch mode on and configured properly.
For example, here is a snippet from my Page schema.
...
{
name: "content",
type: "array",
title: "Page Sections",
description: "Add, edit, and reorder sections",
of: [
{
type: 'reference',
to: [
{ type: 'nav' },
{ type: 'section' },
{ type: 'footer' }
]
}
],
},
...
The above schema references a
nav schema
section schema
footer schema
Each of these are type 'document'.
See the example below.
export default {
type: 'document',
name: 'section',
title: 'Page Sections',
fields: [
{
name: 'meta',
title: 'Section Meta Data',
type: 'meta'
},
...
I want to reference a document, rather than an object, because I need to use the content created based on these schemas to be re-used in throughout the application.
Finally, I've configured the source plugin correctly for watch mode.
Gatsby Config is set properly
{
resolve: `gatsby-source-sanity`,
options: {
projectId: `asdfasdf`,
dataset: `template`,
watchMode: true,
overlayDrafts: true,
token: process.env.MY_SANITY_TOKEN,
},
},
In the CMS / Studio, when you edit one of the fields, you can see Gatsby re-compile in dev mode from the terminal. However, the page does not auto reload and display the changes made to the referenced document.
I've tried reloading the page with the reload button and via hard refresh, the changes do not render.
The only way to render the changes is to go back to the CMS and edit a field on the main “Page” document. Then it refreshes immediately.
Am I doing something wrong? Is this expected behavior? Is there a way to get this to work?
For those that run across this issue, I was able to answer my own question. I hope this saves you the day's it took me to find a solution.
Solution TLDR
You need to explicitly query the referenced document in order for watch mode to work properly.
Details with Examples
Summary
The gatsby-source-sanity plugin provides convenience queries that start with _raw for array types. When you use the _raw query in your GraphQL query, it will not trigger watch mode to reload the data. You need to explicitly query the referenced document in order for watch mode to work properly. This may have to do with how the plugin sets up listeners and I don't know if this is a bug or a feature.
Example
My Page Document has the following schema
{
name: "content",
type: "array",
title: "Page Sections",
description: "Add, edit, and reorder sections",
of: [
{
type: "reference",
to: [
{ type: "nav" },
{ type: 'section' },
],
},
],
},
The section is a reference to a section document.
{ type: 'section' }
The reason I'm not using an object is because I want the page sections to be re-usable on multiple pages.
Assuming you have watch mode enabled properly in your gatsby-config.js file, watch mode, like so...
// gatsby-config.js
{
resolve: `gatsby-source-sanity`,
options: {
projectId: `asdf123sg`,
dataset: `datasetname`,
watchMode: true,
overlayDrafts: true,
token: process.env.SANITY_TOKEN,
},
},
Then you should see the following behavior:
listen for document/content updates
re-run queries, update the data, hot-reload the page
You'll see the following scroll in your terminal window.
success Re-building development bundle - 1.371s
success building schema - 0.420s
success createPages - 0.020s
info Total nodes: 64, SitePage nodes: 9 (use --verbose for breakdown)
success Checking for changed pages - 0.001s
success update schema - 0.081s
success onPreExtractQueries - 0.006s
success extract queries from components - 0.223s
success write out requires - 0.002s
success run page queries - 0.010s - 1/1 99.82/s
This works great if you are querying the main document or any referenced objects. However, if you are querying any references to another document then there is one gotcha you need to be aware of.
The Gotcha
When you use the _raw query in your GraphQL query, it will not trigger watch mode to reload the data. You need to explicitly query the referenced document in order for watch mode to work properly.
Example: This Query will NOT work
export const PageQuery = graphql`
fragment PageInfo on SanityPage {
_id
_key
_updatedAt
_rawContent(resolveReferences: {maxDepth: 10})
}
`
Example: This query WILL Work
export const PageQuery = graphql`
fragment PageInfo on SanityPage {
_id
_key
_updatedAt
_rawContent(resolveReferences: {maxDepth: 10})
content {
... on SanitySection {
id
}
}
}
`
This additional query is the key
Here is where I am explicitly querying the document that is being referenced in the 'content' array.
content {
... on SanitySection {
id
}
}
You don't actually need to use the data that results from that query, you simply need to include this in your query.
My guess is that this informs the gatsby-source-sanity plugin to set up a listener, whereas the _rawContent fragment does not.
Not sure if this is a feature, bug, or just expected behavior. At the time of writing the versions were as follows.
"gatsby": "3.5.1",
"gatsby-source-sanity": "^7.0.0",

react-native-paytm not working

I am trying to use react-native-paytm for payment gateway, I followed the steps what was there in react-native-paytm module, but it is not working for me, Even i don't Know the error and Don't Know how to resolve it
Here is the code that what i have done
payNow(){
// alert("payNow")
var details = {
generationUrl: "https://cinealerts.com/webservices/paytm/xxx.php",
validationUrl: "https://cinealerts.com/webservices/paytm/xxx.php",
mid: "my mid", // Prod
industryType: "Retail", //Prod
website: "APP_STAGING", //prod
channel: "WAP",
amount: "5",
orderId: "12345678",
requestType: "DEFAULT",
email: "hussian#gmail.com",
phone: "7777777777",
theme: "merchant",
custId: "9988344556",
};
paytm.startPayment(details);
}
when i click on button it will call the paynow function, in payNow function one popUp is open and automatically it closed with out showing anything, I don't know how to resolve this issue, and even i don't know that what is the issue.
Any one please give me suggestions that how to resolve this issue, Any help much appreciated.
A better documented fork:
https://github.com/sujayjaju/react-native-paytm
It worked for me on Android. I still need to test on iOS
Make sure you are using the correct values of paytm parameters.
In your code, you are using APP_STAGING in website parameter. It should be APPSTAGING.
To check the correct parameters value of website parameter, follow the steps :-
Log into your Paytm dashborad - https://staging-dashboard.paytm.com
Go to settings->profile
Check value of Website
Also I need to add one more parameter to get it working i.e. mode:'stage'.
I am sharing my code that worked fine for me in android.
var details = {
mid: "my_mid",
industryType: "Retail", //Prod
website: "APPSTAGING", //prod
channel: "WAP",
amount: 100,
orderId: "ORDER_12390",
email: "abc#gmail.com",
phone: 7777777777,
custId: "CUST-12879",
checksumhash: "checksum generated using paytm sdk",
callback: "my_call_back_url",
mode:'stage',
};
// alert(JSON.stringify(details));
paytm.startPayment(details);

Retrieve Project Name

How do you get the project name in Rally?
I'm working with a grid app and all I'm trying to do is include a 'Project' field for the grid view. However, because 'Project' is actually an object, the resulting field is '[object Object]'. So, how is it possible to get the name in string type?
Here's the code from my columnCfgs that deals with making the field.
{
text: 'Project',
dataIndex: this.getContext().getProject().get
},
Try this.getContext().getProject()._refObjectName or this.getContext().getProject().Name
In some cases it is useful to print and explore the object in the console, because it may be that you need to traverse project.data._refObjectName as in this gist, or in your case:
Ext.define('CustomApp', {
extend: 'Rally.app.App',
componentCls: 'app',
items:{ html:'App SDK 2.0 Docs'},
launch: function() {
var currentProject = this.getContext().getProject();
console.log(currentProject);
this.add({
xtype:'container',
html: currentProject.Name
});
}
});

It is possible to have an combobox with two stores in Ext js 4.2?

I have to make a live search , and after hours spent on google I decided to ask here if anyone have an ideea how can I make an live search( using or not combobox) in Ext JS but (the triky part). I have 2 data sets . One data set from one URL and and second from another URL.
I dont know how to start or how can I make the request when I type something in my search box to return small data set first and when is completly loaded second data set ( is much bigger).
Something like when I type "computer" in search field in first block to show me some things related to computers (first request that have few data) after that in second block to show me more thing related to computer when request is over( second request lot of data).
I need this thing because in one of my request i have over 10 k product and i dont want to let user w8 until the request is done, and to show the other request that have fewer data. until the first is done.
I forgot to mention that i want to make both request in the same time and asynchronous.
My solution for exactly this kind of problem was:
Creating a store dedicated only for the combobox content.
When one of the two "source" stores loads data, they push the records into the combo-store.
You also have the reference between the records automatically, so if a record in source-store 1 or 2 is removed, it also disappears in your combostore- and so in your combobox, like magic! Here is the key, for pushing data on load in another store:
http://serversideguy.com/2012/01/31/ext-js-4-merging-store-data/
best regards, hope that helps, write if you need further sugggestion / info on this solution.
If the data is really vital, you can try loading up on memory when the application starts.
Create the stores you need on launch() of the app, load the data and the use it everywhere you want. You can do this on your controller launch() too, to your controller references and granulate this as you wish.
Ext.application({
name: 'Blog',
models: ['Post', 'Comment'],
controllers: ['Posts', 'Comments'],
launch: function() {
Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{name: 'firstName', type: 'string'},
{name: 'lastName', type: 'string'},
{name: 'age', type: 'int'},
{name: 'eyeColor', type: 'string'}
]
});
Ext.create('Ext.data.Store', {
model: 'User',
storeId: 'userStore',
proxy: {
type: 'ajax',
url: '/users.json',
reader: {
type: 'json',
root: 'users'
}
},
autoLoad: true
}); }
});

ExtJS4 / Sencha Touch 2: Reuse data (loaded into store) in different views with different sorting

I have data in an external database which can be accessed via JSON. Now I want to provide different views on these data sets (eg. different sorting, ..). Is it possible to use one single store for this or do I need two stores accessing the same URL except with a different sorter?
My example code looks like this:
Ext.define('MyApp.store.MyStore', {
extend: 'Ext.data.Store',
requires: [
'MyApp.model.MyModel'
],
config: {
autoLoad: true,
model: 'MyApp.model.MyModel',
storeId: 'MyJsonStore',
proxy: {
type: 'ajax',
url: 'http://localhost/index.php?data=MyData&format=json',
reader: {
type: 'json'
}
},
sorters: [
{
direction: 'DESC',
property: 'MyRating'
},
{
direction: 'ASC',
property: 'MyLabel'
}
] } });
And one view should now render a list sorted by the rating and a second one should display a list sorted by the label.
Is there a way to prevent querying the DB twice?
Thanks - I just started out with Sencha Touch and ExtJS --- therefore please excuse my simple question ;)
Somehow I couldn't find any smart solution by asking Google for this basic task..
You don't have to worry about anything unless your two views are presented at the same time. Just re-sort the same store locally.
If they are presented at the same time you will have to create a copy of a store. Otherwise they will show exact same information.