On Nov 18, 8:00 am, Alexey <[EMAIL PROTECTED]> wrote:
> I've a table dic: id, type_id, info
>
> I'd like to store any information inside, it can be, for instance,
> categories with type_id = 1 and classifications with type_id = 2
>
> I'd like to make 2 different models such as
>
> class Category < ActiveRecord::Base
>   set_table_name "dic"
> end
>
> class Сlassification < ActiveRecord::Base
>   set_table_name "dic"
> end
>
> and add conditions to it: type_id = 1 to first, type_id  = 2 to
> second.
>
> In this way i can use Category.find(:all) and don't care about
> classification - they won't be found.
> On the other hand, in Сlassification.find(:all) categories won't be
> found.
>
> Can I add it with RoR?

I'd suggest you use named scopes instead, allowing you to stick with
Rails conventions and benefits.

class Dic < ActiceRecord::Base
 set_table_name 'dic'

 named_scope :categories, :conditions => { :type_id => 1 }
 named_scope :classifications, :conditions => { :type_id => 2 }

end

# Example usage

Dic.categories.all # => returns all categories
Dic.classifications.all # => returns all classifications

Jeff

purpleworkshops.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to