Kristian
Kristian

Reputation: 21820

Rails: can a model have no attributes?

I currently have two models, User and Company. I'm thinking of making a 3rd model that would act as a parent to the other two, and it would be like this:

Account
 - Company
 -- User(s)

The only problem I see with this is that I can't decide whether this model needs any attributes besides an ID.

Is it possible or even useful to have a model that theoretically has no attributes, other than its ID?

Upvotes: 2

Views: 147

Answers (1)

Dinesh Raja
Dinesh Raja

Reputation: 8501

I am not from rails background. But it's like general question from data modelling.

So Ofcourse yes. You can have an object without attributes.

It will be useful to query the certain Account as you modelled. Even If you don't have any attributes, you still have a relationship with Company. So no worries. Go ahead.

An Object without any attribute and relationships is useless. But you have relationship. So it is still useful in its way.

Upvotes: 3

Related Questions