Foreign-key field based on linetype

10 views
Skip to first unread message

Maarten Van Essen

unread,
Feb 19, 2015, 3:45:36 AM2/19/15
to rubyonra...@googlegroups.com
I am a beginner in Ruby on Rails.

I would like to make the following database model:

Package (has_many packagelines)
Packageline (belongs_to package)

The package line can be one of 3 things: entity, item or service, so I
would like to have a line type with the options entity, item or service.
I also want a field where I store the foreign key. The problem is that
the foreign key is dependent on what is selected in the line type field.

Can somebody tell me how I can manage this.

Thanx!

--
Posted via http://www.ruby-forum.com/.

Colin Law

unread,
Feb 19, 2015, 4:56:30 AM2/19/15
to rubyonra...@googlegroups.com
On 19 February 2015 at 08:44, Maarten Van Essen <li...@ruby-forum.com> wrote:
> I am a beginner in Ruby on Rails.
>
> I would like to make the following database model:
>
> Package (has_many packagelines)
> Packageline (belongs_to package)
>
> The package line can be one of 3 things: entity, item or service, so I
> would like to have a line type with the options entity, item or service.
> I also want a field where I store the foreign key. The problem is that
> the foreign key is dependent on what is selected in the line type field.

Before you attempt to solve such issues I would make sure you have a
good understanding of the basics of Rails, as you may well decide the
above is not the best way to solve the problem. I suggest you first
work right through a good tutorial such as railstutorial.org (which is
free to use online) including doing all the exercises. Then
reconsider your problem and come back with further questions if
necessary.

Colin
Reply all
Reply to author
Forward
0 new messages