Tarang
Tarang

Reputation: 75975

Ruby model display only data where key=value

I have a rails project and have a model customers and suppliers. I have a sqlite database table called people. In the customers model I only want to show data from the people table where type=customer and the supplier to only show data from the people table where type=supplier

Its crucial I use the same table for both the models. How would I make the customer model only display type=customer?

Upvotes: 1

Views: 157

Answers (2)

asitmoharna
asitmoharna

Reputation: 1532

Go for single table inheritance. single table inheritance

where u need to inherit customers and suppliers from people.

Upvotes: 3

Yanhao
Yanhao

Reputation: 5294

How about default_scope?

In Customer

default_scope where(:type => 'customer')

In Supplier

default_scope where(:type => 'supplier')

Or, you can use Single table inheritance. Find it here

Upvotes: 1

Related Questions