TypeError: schemaInstance[direction] is not a function - adonis.js

Less of a question and more of an answer. Using AdonisJS and I got this after running: adonis migration:refresh
The issue was that I didn't have the down method defined.
down () {
}

when you refresh the table then required down method because when you revert changes then down method use so more info view documents

Related

Ember.js getJSON data from an url

I am a bit confused. Components, controllers, routes, helpers and whatsoever. I simply want to grab a value from a JSON file and calculate it with a value on Ember.Helper. Which way should i use, i cannot know anymore, brain burned. Would someone please help me to grab the "sell" part of the "market_name" which equals to "BTC_USDT" on "https://stocks.exchange/api2/prices" and put that into helper?
Edited:
In fact i try to do something like that.
import Ember from 'ember';
export function formatBTC(value) {
var url = 'https://stocks.exchange/api2/prices';
var btc_price = Ember.$.getJSON(url).then(function(data) {
for (var i=0; i <= data.length-1; i += 1)
{
if (data[i].market_name == "BTC_USDT")
{
return data[i].sell;
console.log(data[i].sell+' - i got the value properly');
}
}
});
console.log(btc_price+' - shows nothing, i cannot pass the var btc_price to here, why not');
calculation = value * btc_price; //some syntax may apply, maybe Number(value) or whatsoever, but i cannot have my variable btc_price returns here.
return calculation.toFixed(8);
}
export default Ember.Helper.helper(formatBTC);
And from the index.hbs
{{format-btc 0.001}}
Still couldnt find a proper solution. I get the data[i].sell as btc_price, but couldnt pass it through to return part... what am i missing? or what am i doing wrong?
The issue you're encountering is because the ajax request executes. Execution of the function continues and returns the value before the promise returns.
While technically, you could fix this and use async/await in your helper function, you'll run into another issue - Every time your helper is called, you'll make a new ajax request that will fetch the current price and calulate the value.
My recommendation is that instead of a helper, you use a combination of a model and a controller. Because you're currently overwhelmed with the framework, I'll actually make a second suggestion of using a service + component
I recommend a service or a model because you want to persist the data that you've fetched from the pricing source. If you don't, every instance of the helper/component will make a new request to fetch data.
Service
A service is kind of a session collection in ember. It only gets instantiated once, after that data will persist.
ember g service pricing
In the init block, set your default values and make your ajax request.
# services/pricing.js
btcPrice:null,
init() {
this._super(...arguments);
Ember.$.getJSON(...).then(val=>{
# get correct value from response
# The way you were getting the value in your example was incorrect - you're dealing with an array.
# filter through the array and get the correct value first
this.set('btcPrice',val.btcPrice);
})
}
Component
You can then inject the service into the component and use a consistent price.
ember g component format-btc
Modify the controller for the component to inject the service and calculate the new value.
#components/format-btc.js
pricing: Ember.inject.service('pricing')
convertedPrice: Ember.computed('pricing',function(){
return pricing.btcPrice*this.get('bitcoins')
})
The template for the component will simple return the converted price.
#templates/components/format-btc.js
{{convertedPrice}}
And you'll call the component, passing in bitcoins as an argument
{{format-btc bitcoints='1234'}}
All of this is pseudo-code, and is probably not functional. However, you should still be able to take the guidance and piece the information together to get the results you want.

uncaught typeerror: model.save() is not a function - Emberjs 1.13.8

I am new to ember.js, I am trying to save the model from another contoller where i have am able to get all the information of the model. Whenever i try to save the model using the code below
saveModel: function(model) {
model.save();
},
I am getting this error
Uncaught TypeError: model.save is not a function
Any idea how to solve this error?
Model information is getting passed from components using this.sendAction().
this.sendaction() should be CamelCase -> this.sendAction()
Check the Ember Guides for Components -> Handling Events to make sure you are using this.sendAction() correctly
Make sure by debugging that model is being passed correctly from the component.
Had the same error.
Using _internalModel works but is an ugly solution. My mistake was binding the model to the promise
this.set('prop', this.get('store').findRecord('model', id))
and not use
this.get('store').findRecord('user', this.selectedUser.id).then(function(model) {
self.set('prop', model);
});
Hope that this helps someone having the same problem.

Ember Data error when deleting model

I have an Ember-cli app (v2.1), and I'm having an issue with Ember Data when deleting a record from my blog model. Here's the code I'm calling for the deletion:
deleteBlog (blog) {
this.store.findRecord('blog', blog.get('id')).then(blog => {
blog.destroyRecord();
});
}
As expected, Ember Data makes the DELETE request, which works perfectly with my express.js backend service.
The only problem is that the record does not get removed from the Ember Data store, and I get the following error message:
Error: Attempted to handle event pushedData on my-app#model:blog::ember529:56455037f9cf29a325ae72b9 while in state root.deleted.inFlight
I appreciate any feedback!
The problem was in trying to select the model using an instance of the model that I already had. Changing it to a simple:
deleteBlog (blog) {
blog.destroyRecord();
}
got rid of the error! Thanks again to #torazaboro for helping me to take a closer look at the mistake.
Try this:
deleteBlog (blog) {
this.store.findRecord('blog', blog.get('id')).then(function(blog) {
blog.deleteRecord(); // => remove blog from the store
blog.save(); // => DELETE request
});
}
But this is supposed to do the same as blog.destroyRecord(); so it may not work.
What is probably happenning is that if you have a request to the server in-flight and you delete the model then you get an exception Attempted to handle event pushedData on model while in state root.deleted.uncommitted.

why does my emberjs model throw an exception when i try calling deleteRecord on it

I am doing this tutorial and just when i thought i got everything right, I came across this exception
JavaScript runtime error: Object doesn't support property or method 'deleteRecord'
in this context
removeTodo: function () {
var todo = this.get('model');
todo.deleteRecord();
todo.save();
}
i trying to follow the getting started tutorial on the Ember.js site.
It would appear that your model isn't actually a DS.Model (assuming that you're using Ember Data). Unless you're model is an actual record I'm ember, you won't be able to call delete record.

Ember Transaction has no method add

I'm attempting to create an ember transaction to commit a single model to the backend api.
Coffeescript:
comic = App.Comic.createRecord(title: #get('comicTitle'))
transaction = comic.get('store').transaction
transaction.add(comic)
transaction.commit()
Which gives the javascript error:
Uncaught TypeError: Object function () {
return DS.Transaction.create({ store: this });
} has no method 'add'
I've googled various different ways to use ember transactions, but I'm not sure where I'm going wrong. I'm using the latest version of ember data.
The coffeescript to js translation may not be happening correctly. Try changing to
transaction = #get('store').transaction()
I have found the implicit method invocation in coffeescript trips up in Ember occasionally.