<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<font size="-1"><font face="Helvetica, Arial, sans-serif">Ah, this one
I do know about. :) If you are using MySQL, it actually needs to be:</font></font><br>
<pre wrap="">:conditions => "movies = 1"</pre>
<font size="-1"><font face="Helvetica, Arial, sans-serif"><br>
As there are no true boolean fields in MySQL - it's actually just a
tinyint with values of either 0 (for false) or 1 (for true). The only
problem that I can possibly see with the above method is that it looks
like (according to my good friend, Google) other databases <i>might</i>
store true/false queries differently and so if you were to need to
switch to a different database then you <i>might</i> have to change
this code. I'm sure others could enlighten us on this subject. <br>
<br>
</font></font>
<div class="moz-signature">
<div style="line-height: 125%;"> <img
src="cid:part1.08020906.05030301@gnexp.com" height="49" width="136"><br>
<span style="font-family: Arial,Helvetica,sans-serif; font-size: 9pt;"><b>Jeremy
Nicoll</b><br>
<a href="http://www.gnexp.com">www.gnexp.com</a><br>
(801) 783-3831 </span>
</div>
</div>
<br>
<br>
Larry E. Lutz wrote:
<blockquote
cite="mid:!&!AAAAAAAAAAAYAAAAAAAAAJEa5KrSnKZOu8NPJG9qB4fCgAAAEAAAADiPoz%2F8J9BPv5uD3u069LEBAAAAAA==@swbell.net"
type="cite">
<pre wrap="">I have a "categories" table, set up as a nested set, that I want to use to
categorize a number of different types of things, such as books, software,
movies, etc. Since the table is rather large (over 3,000 rows), I would like
to be able to pull subsets of the table for the different types of things. I
can't use a singleton because the same category can apply to more than one
type of thing, and in many cases, a category set for a type of thing may
start a level below the root. In lieu of that, I have several Boolean fields
within the table for the different types of things. The problem is that, no
matter where I try to apply a scope or condition, the system seems to ignore
it and, instead, returns the full dataset.
My schema looks like this:
create_table "categories", :force => true do |t|
t.column "parent_id", :integer
t.column "lft", :integer
t.column "rgt", :integer
t.column "topic", :string, :default => "", :null => false
t.column "description", :text
t.column "books", :boolean, :default => true
t.column "entities", :boolean, :default => false
t.column "movies", :boolean, :default => false
t.column "music", :boolean, :default => false
t.column "software", :boolean, :default => false
t.column "tech_articles", :boolean, :default => false
end
Within the data in this table, "Movie Genres," for instance, is not a root
level record. Instead, it is buried several layers deep under the
"Performing Arts" root. The identifier for Movie Genres is the Boolean field
"movies."
With set_table_name "categories", here are some of the things that I've
tried that don't work:
------------------------------------------
has_many :children, :class_name => "MovieGenre", :foreign_key =>
:parent_id, :conditions => "movies = true"
belongs_to :parent, :class_name => "MovieGenre"
----------------------------------------
has_many :children, :class_name => "MovieGenre", :foreign_key =>
:parent_id, :conditions => "movies = true"
belongs_to :parent, :class_name => "MovieGenre", :foreign_key =>
:parent_id, :conditions => "movies = true"
acts_as_nested_set :scope => 'movies = true'
has_many :children, :class_name => "MovieGenre"
belongs_to :parent, :class_name => "MovieGenre"
----------------------------------------------
Is there anyway to achieve what I need to accomplish? I really don't want to
go to multiple "categories" tables for each kind of thing because I need to
keep the categories consistent. By the way, I would also like to have a
"long name" returned when I pull the subset, like this:
def long_name
self_and_ancestors.map{ |a| a.topic}.join(' > ')
end
However, that's not absolutely essential. I do need to be able to use the
returned dataset both in a listing and in a select form field.
Any ideas folks?
Larry E. Lutz
2425 Sage Road, Apt. 53
Houston, Texas 77056
(713) 850-1358
<a class="moz-txt-link-abbreviated" href="mailto:lutzle@swbell.net">lutzle@swbell.net</a>
</pre>
<pre wrap="">
<hr size="4" width="90%">
_______________________________________________
Betternestedset-talk mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Betternestedset-talk@rubyforge.org">Betternestedset-talk@rubyforge.org</a>
<a class="moz-txt-link-freetext" href="http://rubyforge.org/mailman/listinfo/betternestedset-talk">http://rubyforge.org/mailman/listinfo/betternestedset-talk</a>
</pre>
</blockquote>
</body>
</html>