Forum: Ruby on Rails Complex Association - Please help

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Hirak (Guest)
on 2009-06-05 12:43
(Received via mailing list)
Hi All,
         I am a newbie in rails. I am creating a new rails
application. Here I have 4 models.

1. User
2. Item
3. Application
4. Tag

The concept is

- Item belongs to User
- Item has many Tags
- Item has many application through tags
- Tags are hierarchical (i.e a tree structure, a child tag can be
related to a parent tag.)


Please help me, how to handle these Associations.

Thanks
Hirak
Sandip R. (Guest)
on 2009-06-05 12:57
(Received via mailing list)
comments inline

On Fri, Jun 5, 2009 at 1:57 PM, Hirak <removed_email_address@domain.invalid> 
wrote:

>
> Hi All,
>         I am a newbie in rails. I am creating a new rails
> application. Here I have 4 models.
>
> 1. User
> 2. Item
> 3. Application
> 4. Tag

ok

>
>
> The concept is
>
> - Item belongs to User
> - Item has many Tags


It means you have tags table will have item_id

- Item has many applications through tags


for above you must have some relations between application and tags
table.

- Tags are hierarchical (i.e a tree structure, a child tag can be
> related to a parent tag.)


tag belongs_to parent_tag :class_name => "Tag", :foreign_key =>
"parent_id"

You must have parent_id field in tags table.
If parent_tag is nil then you can identify tag as child_tag

>
>
>
> Please help me, how to handle these Associations.
>
> Thanks
> Hirak
>

hope this will help !

-Sandip R~


> >
>
--
Ruby on Rails Developer
http://sandip.sosblog.com
http://funonrails.wordpress.com
www.joshsoftware.com
Hirak (Guest)
on 2009-06-05 13:08
(Received via mailing list)
On Jun 5, 1:56 pm, Sandip R. <removed_email_address@domain.invalid> wrote:
> > 3. Application
>
> tag belongs_to parent_tag :class_name => "Tag", :foreign_key => "parent_id"
>
> hope this will help !
>
> -Sandip R~
>
>
>
> --
> Ruby on Rails 
Developerhttp://sandip.sosblog.comhttp://funonrails.wordpre...



Thanks Sandip you got it almost right, but what I meant is

Items table will have tag_id

How that association needs to be handled ?

Thanks again for your reply.

-- Hirak
This topic is locked and can not be replied to.