Todd Benson
3/25/2008 5:24:00 PM
On Tue, Mar 25, 2008 at 9:48 AM, Joan Gu <joan2kus@gmail.com> wrote:
> I need to insert Broad Category value and Topics value into a table,
> doing something like this (where 'Police, Crime, Drugs' are topics
> values and 'Crime & Law Enforcement' is broad category value):
>
> obj1 = 'Police, Crime, Drugs'
> obj1 = obj1.split(',').map do |tag_name|
> execute "insert into tags (name,counter) values
> ('#{tag_name.strip.downcase}', 0)"
> t = Tag.find_by_name(tag_name.strip.downcase)
> tt = t.tag_with('Crime & Law Enforcement')
> end
>
> When it comes with multiple broad categories and topics, I want to build
> an array in a form like
> [['Police, Crime, Drugs','Crime & Law Enforcement'],['Fire, Emergency
> Services','Emergency Management'], ['Schools, Colleges,
> Libraries','Education'],...]
> to iterate the executions. I worked for quite some hours, but still
> can't make it work. Can someone help?
>
> Joan
Can't help you with migrations, but what's your relationship model?
Is it one to one and that's why you want an array like that? Is it
one many (which is what I'd suspect)? Is it many to many?
You did say "a" table. Somehow, that doesn't seem to correctly fit your model.
Todd