0

I'm writing a rails project that is about stock market. There is a ticker symbol that represent a company. e.g. "AAPL" for Apple.

But the ticker symbol is only unique for current listed companies, the symbols are duplicated when delisted companies are included. And I want to include also delisted companies to the system.

Currently I'm thinking to create two columns for ticker symbols like ticker and ticker_for_friendly_id. And only currently existing companies have both values and delisted companies only have ticker values.

But to save same value in two columns are bit redundant, is there a better way to implement it situation like this?

ironsand
  • 14,329
  • 17
  • 83
  • 176
  • can you give me an example which delisted company is using the symbol of a current company ? – Tim Kretschmer Sep 19 '15 at 06:30
  • 1
    I don't think you understand the purpose of FriendlyId gem... It CREATES slugs based on other attributes in your models. In your case you don't create tickers because they are defined by stock market, you just need an indexed column and `find_by` – Mike Szyndel Sep 19 '15 at 16:50

1 Answers1

2
friendly_id :slug_candidates, use: :slugged

def slug_candidates
  [
    :ticker_slug
  ]
end

def ticker_slug
  str = ticker
  str += '-unlisted' if unlisted?
end
penner
  • 2,707
  • 1
  • 37
  • 48