Problem with using global search


I have created my model assets and controller, including previews for entities like users and organizations. However, when I attempt to use global search without first loading these entities by opening them in the controller , it does not work, and I receive errors. Although all relationships exist and everything functions correctly when not using global search, the issue persists specifically with the global search feature.

class App.Asset extends App.Model
	@configure 'Asset','form_id', 'name', 'serial_number', 'organization', 'user', 'invoice', 'files', 'model', 'seller', 'purchase_date', 'purchase_cost', 'description'
	@extend Spine.Model.Ajax
	@url: @apiPath + '/assets'
	@configure_attributes = [
		{ name: 'name', display: __('Nazwa'), tag: 'input', null: false, },
		{ name: 'serial_number', display: __('Numer seryjny'), tag: 'input',null: false },
		{ name: 'organization::name', display: __('Organization'), tag: 'autocompletion_ajax_customer_organization', multiple: false, null: false, relation: 'Organization', },
		{ name: 'user::firstname', display: __('User'), tag: 'autocompletion_ajax', relation: 'User', null: true, },
		{ name: 'invoice_present', display: __('Faktura'), tag: 'input', null: false, },
		{ name: 'attachments_count', display: __('Załączniki'), tag: 'input',null: true, },
		{ name: 'model', display: __('Aktywo'), tag: 'autocompletion_ajax', relation: 'Model', null: true, },
		{ name: 'seller', display: __('Sprzedawca'), tag: 'autocompletion_ajax', relation: 'Seller', null: true,},
		{ name: 'purchase_date', display: __('Data kupna'), tag: 'date', class: 'input', null: true },
		{ name: 'purchase_cost', display: __('Koszt kupna'), tag: 'decimal', null: true},
		{ name: 'description', display: __('Opis'), tag: 'textarea',upload:true, class: 'input', null: true},
	]
	@configure_overview = [
		'name', 'serial_number', 'organization::name', 'user::firstname', 'invoice', 'files', 'model_id', 'seller_id', 'purchase_date', 'purchase_cost', 'description'
	]
	@configure_preview = [
		'name', 'serial_number', 'organization::name', 'user::firstname', 'invoice', 'files', 'model_id', 'seller_id', 'purchase_date', 'purchase_cost', 'description'
	]
	icon: ->
		'overviews'

	uiUrl: ->
		"#manage_assets/preview/asset/#{@id}"

	displayName: ->
		if !_.isEmpty(@name)
			name = @name

	searchResultAttributes: =>
		display: "#{@displayName()}"
		url: @uiUrl()
		id: @id
		icon: "#{@icon()}"

Can you click in the upper traceback and screenshot them so we can see where the error is coming from?

I managed to solve this problem, but I have another one related to (which is related to this one) my it turned out that I don’t have the function in the @_fillUp model that adds relationships from which later information is extracted (this is done in the user’s model and the organization and it works there ) I did the same thing, however, with my other models and it looks like they are not started in memory because when I call them in another place the relationship works

Now my model looks like this

class App.Asset extends App.Model
  @configure 'Asset','form_id', 'name', 'serial_number', 'organization', 'user', 'invoice', 'files', 'model', 'seller', 'purchase_date', 'purchase_cost', 'description'
  @extend Spine.Model.Ajax
  @url: @apiPath + '/assets'
  @configure_attributes = [
          { name: 'name', display: __('Nazwa'), tag: 'input', null: false, },
          { name: 'serial_number', display: __('Numer seryjny'), tag: 'input',null: false },
          { name: 'organization_id',  display: __('Organization'), relation: 'Organization'},
          { name: 'user_id', display: __('User'), relation: 'User', width: '12%'},
          { name: 'invoice', display: __('Faktura'), tag: 'file_upload', single: true, null: true, },
          { name: 'files', display: __('Załączniki'), tag: 'file_upload', single: false, null: true, },
          { name: 'model_id', display: __('Aktywo'), relation: 'Model', null: true, },
          { name: 'seller_id', display: __('Sprzedawca'), tag: 'autocompletion_ajax', relation: 'Seller', null: true,},
          { name: 'purchase_date', display: __('Data kupna'), tag: 'date', class: 'input', null: true },
          { name: 'purchase_cost', display: __('Koszt kupna'), tag: 'decimal', null: true},
          { name: 'description', display: __('Opis'), tag: 'textarea',upload:true, class: 'input', null: true},
        ]
  @configure_overview = [
    'name', 'serial_number', 'organization', 'user', 'invoice', 'files', 'model', 'seller', 'purchase_date', 'purchase_cost', 'description'
  ]
  @configure_preview = [
    'name', 'serial_number', 'organization', 'user', 'invoice', 'files', 'model', 'seller', 'purchase_date', 'purchase_cost', 'description'
  ]
  icon: ->
    'overviews'

  uiUrl: ->
    "#manage_assets/preview/asset/#{@id}"

  displayName: ->
    if !_.isEmpty(@name)
      name = @name

  @_fillUp: (data) ->
    if data.organization_id
      data.organization = App.Organization.findNative(data.organization_id)
      console.log data.organization
    if data.model_id
      data.model = App.Model.findNative(data.model_id)
      console.log data.model
    if data.seller_id
      data.seller = App.Model.findNative(data.seller_id)
      console.log data.seller
    data

  searchResultAttributes: =>
    display: "#{@displayName()}"
    url: @uiUrl()
    id: @id
    icon: "#{@icon()}"

the data in the table looks like this

image

and these are the console.logs from the _fillUp function

I don’t know what the models are on your side but these lines look like a problem:

    if data.model_id
      data.model = App.Model.findNative(data.model_id)
      console.log data.model
    if data.seller_id
      data.seller = App.Model.findNative(data.seller_id)
      console.log data.seller

It must be like App.Seller.find. Also App.Model is a blocked namespace, I think. You need to rename it to App.AssetModel or something so you don’t issues.

Also if you want your data ready for your fillup function you need to serve them in your assets. Many models have dedicated asset files on the backend side see some examples here:

You will need something similar for your Asset model so that you can auto load the seller and the “model” with it.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.