I have a Series model which $hasMany RainLab\Blog\Models\Posts and when I display this model with 'type' => 'relation', in Posts form it looks perfectly fine:
So, I can select one Series and assign it to a Post. What I wanted to do is to be able to create new series while being on Posts page. To do this I tried to use 'type' => 'partial' for Series field. Partial itself contains just:
<?= $this->relationRender('series', ['readOnly' => false]) ?>
config_relation.yaml contents:
series:
label: Series
view:
list: $/plugin/models/series/columns.yaml
form: $/plugin/models/series/fields_simple.yaml
toolbarButtons: link|unlink|create|add|remove
manage:
form: $/plugin/models/series/fields_simple.yaml
columns.yaml contents:
# ===================================
# List Column Definitions
# ===================================
columns:
title:
label: Title
searchable: true
post_count:
label: Posts
sortable: false
created_at:
label: Created At
type: date
invisible: true
updated_at:
label: Updated At
type: date
invisible: true
fields_simple.yaml:
# ===================================
# Form Field Definitions
# ===================================
fields:
title:
label: Title
span: left
required: true
slug:
label: Slug
span: right
placeholder: Slug
required: true
preset:
field: title
type: slug
So, basically, nothing special here. But:
As you see, it looks terrible by default. And one more issue - when deleting the series (or unlinking, I tried both) it does not refresh the form, values remain there, though the relation is removed in DB.
Am I doing anything wrong here? What is the proper way to nicely display this relation with ability to edit it?
Related
I have a model with 3 entities, Documents, Employees and Managers. A Document belongs to and Employee and an Employee belongs to a Manager.
My objective is to retrieve all the documents of a manager employees.
My piece of code is working
Document.findAll({
include: [{
model: models.Employee,
required: true,
as: 'employee',
include: [{
model: models.Manager,
required: true,
as: 'manager',
}],
}],
But I'm not really satisfied, I would like to have my where condition outside my include but when I try
where {
'employee.manager.id': id
}
an error is raised.
Is it possible to setup a where condition outside the includes ?
EDIT :
I changed my code to
Document.findAll({
where: {'$employee.manager.id$': id},
include: [{
model: models.Employee,
required: true,
as: 'employee',
include: [{
model: models.Manager,
required: true,
as: 'manager',
where: { id: managerId },
}],
}],
and it's working.
Now, I would like to refine my model. Each document as a type (administrative, evaluation ...) and I would like to retrieve the most recent document for each type for each manager. I used an order by which is working fine and tried to use a group by which is not working
order: [ [ 'updatedAt', 'DESC' ]],
group: ['type'],
I get the following message : column \"Document.id\" must appear in the GROUP BY clause or be used in an aggregate function.
Any idea what I'm doing wrong ?
Yes, you can do that ,
Issue with current one :
where {
'employee.manager.id': id // <--- Here 'employee.manager.id' cosidered as whole column name
}
Solution :
where {
'$employee.manager.id$': id //<--- To make sequlize realize you need to place it b/w $$ ,
//or
sequelize.col('employee.manager.id') : id // <--- You can try this also
}
I know that this is a simple question, but I got stuck looking for a solution.
First, I got the FormPanel, that obtains data passed by JSON that looks like:
var formPanel = new Ext.FormPanel({
....
[
{name: 'country', mapping: 'country'}
]
...
Then, I populate the store with data from an external file that has a list of countries
var countryStore = new Ext.data.SimpleStore({
fields: ['vcountry', 'vcountrydesc'],
data : Ext.ms.data.countries,
id:1,
});
What I want to do is to set a default value in a Ext.form.ComboBox, which is defined as name: 'country', precisely, I want to do something like this:
var countryFld = new Ext.form.ComboBox({
store: countryStore,
.....
mode: 'local',
forceSelection: true,
triggerAction: 'all',
emptyText: 'Select Country',
value: 'country', **<---I WANT TO DO THIS, BUT TO DISPLAY A VALUE, NOT A STRING!**
....
}
});
I assume that solution is very simple, but I got stuck on it.
SIMPLE, very stupid of me to ask...
Solution is just like for any other form
dataIndex: 'country',
instead of
value:'country',
I would like to know how to iteratively create picklists (dropdowns) from a json collection.
I have two desired columns, one representing the 'primary' category, and the other representing the 'secondary' category.
I'd like for the right column to have just a string for every 'primary' category and then the left column will have a picklist with options for secondary category. What i'm also trying to do is group this by type. So there will essentially be sections of picklists grouped by type. One section with two columns of 'string', and then another section below that one with two columns of 'number', etc.
--Numbers--
Column 1 || Column 2
Label || picklist
--Strings--
Column 1 || Column 2
Label || picklist
--Booleans--
Column 1 || Column 2
Label || picklist
function MyCtrl($scope) {
$scope.players = [
{type: 'String', org: 'primary', name: 'something__c', label: 'Something'},
{type: 'Number', org: 'primary', name: 'something_else__c', label: 'Something Else'},
{type: 'String', org: 'primary', name: 'obscure__c', label: 'Obscure'},
{type: 'String', org: 'primary', name: 'else__c', label: 'Else'},
{type: 'String', org: 'secondary', name: 'some__c', label: 'Some'},
{type: 'Number', org: 'secondary', name: 'thing__c', label: 'Thing'},
{type: 'Number', org: 'secondary', name: 'sanity_check__c', label: 'My Sanity'}
];
}
Using the tutorials i was only able to get as far as what is in this fiddle: http://jsfiddle.net/GV7KZ/5/
Thank you for any and all guidance.
I'm assuming you mean 'org' instead of category, given that org is the only node with the values of 'primary' and 'secondary'. I thing perhaps you want to use 'filter' rather than your custom 'group by' filtering.
I've made some changes to your fiddle separating out the two. Let me know if this gets you closer to what you want.
<tr ng-repeat="player in players|filter:'primary'">
<td>
{{player.label}}
</td>
<td>
<select>
<option ng-repeat="player in players|filter:'secondary'" value="{{player.name}}">{{player.label}}</option>
</select>
</td>
http://jsfiddle.net/GV7KZ/6/
I've just started to get into the framework of Sails for Node. But it seems like I can't get the unique- requirements to work when adding for example users to the sails-mysql database. I can atm add unlimited number of new users with the same username and email.
From what I have read it should work, I did also try with sails-memory and there this exact code did work. Is it something I have missed out?
module.exports = {
attributes: {
username: {
type: 'string',
required: true,
unique: true
},
firstname: {
type: 'string',
required: true
},
lastname: {
type: 'string',
required: true
},
password: {
type: 'string',
required: true
},
birthdate: {
type: 'date',
required: true
},
email: {
type: 'email',
required: true,
unique: true
},
phonenumber: 'string',
// Create users full name automaticly
fullname: function(){
return this.firstname + ' ' + this.lastname;
}
}
};
As I mentioned above, this does work with the memory-storage. And now I have also tried with mongodb where it does work fins as well.
Got support from Sails.js on twitter: "it uses the db layer- suspect it's an issue with automigrations. Would you try in a new MySQL db?"
This answer did work, a new db and everything was just working :)
Just to add to this, since sails uses auto-migrations, if you initially start the server and your model does not have an attribute as unique, the table is built without the unique (index) switch. If you then change an existing attribute in the model to unique, the table will not be rebuilt the subsequent times you start the server.
One remedy during development is to set migrations in your model to drop like this:
module.exports = {
migrate: 'drop' // drops all your tables and then re-create them Note: You loose underlying.
attributes: {
...
}
};
That way, the db would be rebuilt each time you start the server. This would of course drop any existing data as well.
I've trouble with my Combobox. I've build a simple combobox which is configured with a JsonStore to provide remote data. The combobox opens at the first click without problems, the JSON data is requested and Ext shows me the full dropdown list.
But sporadly at the second (sometimes third) click, the combobox neither open nor load any remote data.
Here's my config:
var config = {
autoLoad: true,
fields: [{
name: 'name',
type: 'string'
}, {
name: 'count',
type: 'int'
}, {
name: 'created_at',
type: 'int'
}, {
name: 'updated_at',
type: 'int'
}],
root: 'result',
idProperty: 'id',
proxy: new Ext.data.HttpProxy({
method: 'GET',
url: '/myHandler/loadDropDownList'
})
};
The combobox itself is loaded in a toolbar:
var config = {
height: 27,
items: [{
xtype: 'tbtext',
text: 'Your preference?:',
// #todo inline style -> CSS
style: {
'font-weight': 'bold',
'color': '#15428B',
'font-family': 'tahoma,arial,verdana,sans-serif',
'font-size': '11px'
}
},
'->',
// align the following items on the right side of the toolbar
{
xtype: 'combo',
itemId: 'table-combobox',
store: new myStore(),
valueField: 'name',
displayField: 'name',
value: ' - Please Choose - '
}]
}
Many thanks in advance!
The combobox may be running into trouble querying the database everytime you select it. If you don't need the combobox data to be updated throughout a user's session (i.e. the dropdown values don't change in between the times the user clicks the combobox), you can add this config to the combobox:
mode:'local',
(ExtJS4: queryMode:'local')
It will take the data that the remote store has autoLoaded and will not requery the database store every time it is dropped down.