New db fields in listing model

Hello,

I have created a few new fields in Listing model.
I am trying to display data from those fields on the manage listings (index) page, but getting nil values though there are values in those fields.
Those same values are being displayed okay on show page, just not on index page.
Any ideas?

Thanks

1 Like

Can you share your code changes to show these fields?

Hi Zenik,

listing_index_view_utils.rb:

module ListingIndexViewUtils
ListingItem = Struct.new(
:id,
:url,
:title,
:category_id,
:latitude,
:longitude,
:distance,
:distance_unit,
:author,
:description,
:listing_images,
:price,
:unit_tr_key,
:unit_type,
:quantity,
:shape_name_tr_key,
:listing_shape_id,
:icon_name,
:company_name,
:contact_name,
:email,
:phone,
:duration,
:job_status,
:payment,
:other_comments)

in the same file added new fields in ListingItem.new()
ListingItem.new(
l[:id],
l[:url],
l[:title],
l[:category_id],
l[:latitude],
l[:longitude],
l[:distance],
l[:distance_unit],
author,
l[:description],
listing_images,
l[:price],
l[:unit_tr_key],
l[:unit_type],
l[:quantity],
l[:shape_name_tr_key],
l[:listing_shape_id],
l[:icon_name],
l[:company_name],
l[:contact_name],
l[:email],
l[:phone],
l[:duration],
l[:job_status],
l[:payment],
l[:other_comments]
)
}

new migration:
class AddFieldsToListings < ActiveRecord::Migration[5.1]
def change
add_column :listings, :company_name, :string
add_column :listings, :contact_name, :string
add_column :listings, :email, :string
add_column :listings, :phone, :string
add_column :listings, :duration, :string
add_column :listings, :job_status, :string
add_column :listings, :agreed_fees, :string
add_column :listings, :payment, :string
add_column :listings, :other_comments, :text
end
end

These newly added columns work, they are saved while creating a listing, displays the data on show page, but returns nil on listing index page.

Thanks.

1 Like

Check also these files to update Listing entities definitions:

app/services/listing_index_service/search/converters.rb
app/services/listing_index_service/data_types.rb

Thank you very much Zenik. It worked.

@zenik can you let me know I want to show near by listings so how can I use the existing search for nearby listings radius must be 50km.

You can try my patch for location search with sphinx: https://github.com/sharetribe/sharetribe/pull/3256