<!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">&nbsp;&nbsp;&nbsp; Of
course, <i>children</i> and <i>parent</i> are also methods used by
BNS, the methods override ActiveRecord's way of handling the
associations.&nbsp; Sorry - did not quite get what you were asking before.&nbsp;
It seems the children method does not work as other AR associations
either.&nbsp; So you can't do an AR find like <i>record.children.find(:all,
:conditions =&gt; 'something = 1').&nbsp; <br>
<br>
&nbsp;&nbsp;&nbsp; </i>To be quite honest, I'm still not sure what your intent is.&nbsp;
Are all movies going to be grouped together?&nbsp; It seems like with your
db setup that it is quite possible to have movies spread all over the
database, which when the records are by themselves would render the <i>parent</i>
and <i>children</i> methods quite useless.&nbsp; </font></font><font
 size="-1"><font face="Helvetica, Arial, sans-serif">If you could
explain more fully why you want to do this and what the expected
outcome is, that would be most helpful. </font></font><br>
<font size="-1"><font face="Helvetica, Arial, sans-serif"><br>
</font></font>
<div class="moz-signature">
<div style="line-height: 125%;"> <img
 src="cid:part1.02090906.06060708@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>
Jeremy Nicoll wrote:
<blockquote cite="mid:47E3C85D.7040609@gnexp.com" type="cite">
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <font size="-1"><font face="Helvetica, Arial, sans-serif">Ah, this
one
I do know about.&nbsp; :)&nbsp; If you are using MySQL, it actually needs to be:</font></font><br>
  <pre wrap="">:conditions =&gt; "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&nbsp; 0 (for false) or 1 (for true).&nbsp; 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.&nbsp; 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:part2.00040602.00060201@gnexp.com" height="49" width="136"><br>
  <span style="font-family: Arial,Helvetica,sans-serif; font-size: 9pt;"><b>Jeremy
Nicoll</b><br>
  <a moz-do-not-send="true" 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:!&amp;!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 =&gt; true do |t|
    t.column "parent_id",     :integer
    t.column "lft",           :integer
    t.column "rgt",           :integer
    t.column "topic",         :string,  :default =&gt; "",    :null =&gt; false
    t.column "description",   :text
    t.column "books",         :boolean, :default =&gt; true
    t.column "entities",      :boolean, :default =&gt; false
    t.column "movies",        :boolean, :default =&gt; false
    t.column "music",         :boolean, :default =&gt; false
    t.column "software",      :boolean, :default =&gt; false
    t.column "tech_articles", :boolean, :default =&gt; 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 =&gt; "MovieGenre", :foreign_key =&gt;
:parent_id, :conditions =&gt; "movies = true"
  belongs_to :parent, :class_name =&gt; "MovieGenre"
----------------------------------------
  has_many :children, :class_name =&gt; "MovieGenre", :foreign_key =&gt;
:parent_id, :conditions =&gt; "movies = true"
  belongs_to :parent, :class_name =&gt; "MovieGenre", :foreign_key =&gt;
:parent_id, :conditions =&gt; "movies = true" 
  acts_as_nested_set :scope =&gt; 'movies = true'
  has_many :children, :class_name =&gt; "MovieGenre"
  belongs_to :parent, :class_name =&gt; "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(' &gt; ')
  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 moz-do-not-send="true" 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 moz-do-not-send="true" class="moz-txt-link-abbreviated"
 href="mailto:Betternestedset-talk@rubyforge.org">Betternestedset-talk@rubyforge.org</a>
<a moz-do-not-send="true" class="moz-txt-link-freetext"
 href="http://rubyforge.org/mailman/listinfo/betternestedset-talk">http://rubyforge.org/mailman/listinfo/betternestedset-talk</a>
  </pre>
  </blockquote>
  <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>