Smart View: related data missing

Hi,
I have these two tables that are linked by a foreign key with a has_many relationship. Following are the models that I have implemented:

  1. Handlers:
const Handlers = (sequelize: any, DataTypes: any) => {
	const Model = sequelize.define(
		'handlers',
		{
			...
		},
		{
			tableName: 'Handlers'
		}
	);

	Model.associate = (models: any) => {
		Model.hasMany(models.missions, {
			foreignKey: {
				name: 'handlerIdKey',
				field: 'handlerId'
			},
			as: 'handlerMissions'
		});
	};

	return Model;
};
  1. Missions:
const Missions = (sequelize: any, DataTypes: any) => {
	const Model = sequelize.define(
		'missions',
		{
			...
		},
		{
			tableName: 'Missions'
		}
	);

	Model.associate = (models: any) => {
		Model.belongsTo(models.handlers, {
			foreignKey: {
				name: 'handlerIdKey',
				field: 'handlerId'
			},
			as: 'handler'
		});
	};

	return Model;
};

Smart View:
component.js

...
missionList: Ember.computed(
	'currentRecord.forest-handlerMissions.@each',
	function () {
		return this.get('currentRecord.forest-handlerMissions').map(
			function (mission) {
				return mission;
			}
		);
	}
),
actions: {
	selectRecord: function (record) {
		this.set('currentRecord', record);
	}
}
...

template.hbs
// snippet 1

{{#each records as |record|}}
	<a href="#" {{action "selectRecord" record}}>
		<h4>{{record.forest-handlerMissions.length}}</h4>
	</a>
{{/each}}

// snippet 2

{{#each missionList as |mission|}}
...
{{/each}}

Expected behavior

Snippet 1 should display the number of mission a handler has.

Snippet 2 should display the current handler’s missions

Actual behavior

The maximum number that appears is 10.

The maximum missions that appears are 10.

  • Package Version: forest-express-sequelize 6.3.11
  • Express Version: 4.17.1
  • Sequelize Version: 5.8.9
  • Database Dialect: postgres
  • Database Version: 12
  • Project Name: Kokoon

Found a solution:

...
		var currentRecordId = this.get('currentRecord').get('id');

		const params = {
			filters: JSON.stringify({
				conditions: [
					{
						field: 'handlerId',
						operator: 'equal',
						value: currentRecordId
					}
				]
			}),
			timezone: 'America/Los_Angeles',
			'page[number]': 1,
			'page[size]': 50
		};

		this.get('store')
			.query('forest-mission', params)
			.then((missions) => {
				this.set('missionList', missions);
			});

...

Got the missions of a handler with query and then assigned the value to missionList.

1 Like

Hi @Adil_Niaz,

Thank you for reaching out with your issue.

As stated in our documentation, when fetching data you need to provide the pagination parameters: page number and page size. By default you’ll get the first page with 10 records.

Regards

2 Likes