I will send a pull request.

I am thinking that an entry into thinking sphinx by its rake tasks
could set a flag, or otherwise the index building code in general
should follow the principle of failing fast. For entry into the code
otherwise, load_models can be called with a quiet flag. Although, I am
wondering why the models need to be loaded immediately in that case?

On Jun 13, 9:14 am, Pat Allan <[email protected]> wrote:
> Hi Greg
>
> Thanks for figuring out the cause - great detective work!
>
> I'm not sure about the patch at the moment, but will try to look over  
> it in detail, and I'll let you know my thoughts. If you could send me  
> a pull request for it, just so I won't forget about it.
>
> As for error messages, I guess there's two opposing approaches. The  
> current fail-quietly approach is because sometimes people run their  
> migrations (or db:create) and TS fails to load because the tables  
> aren't there. It shouldn't fail in those occasions, because those  
> kinds of problems should be expected, and aren't critical.
>
> However, as you've rightly found, this gets in the way of normal  
> debugging. If we can find some way of making both situations work  
> nicely, that'd be fantastic.
>
> Cheers
>
> --
> Pat
>
> On 11/06/2009, at 11:41 PM, Greg Weber wrote:
>
>
>
> > I am using ts as a plugin. The problem was with class loading.
>
> > The problems I had occur in part because define_index is immediately
> > evaluated. When I made a couple changes and moved my association above
> > the define_index it fixed the problem. Here is a patch to promise to
> > evaluate the define indexes after the models have been loaded, which
> > entirely fixes this issue.
> >http://github.com/gregwebs/thinking-sphinx/commit/42eb19a31c3052adf63...
> > It breaks a lot of tests, but hopefully none of them actually indicate
> > a bug. Let me know if you are serious about taking the patch in and I
> > will work to fix the tests.
>
> > Debugging this problem took a long time in part because thinking
> > sphinx keeps going after being in an invalid state, and did not report
> > error messages. It is usually best to fail with as much info as early
> > as possible. So I hope you will apply my patch to print error
> > messages, and it would be great to come up with a way to throw an
> > error if there are no attributes.
>
> > On Jun 11, 7:45 pm, Pat Allan <[email protected]> wrote:
> >> Hi Greg
>
> >> Are you using Thinking Sphinx as a gem or a plugin?
>
> >> Also, you *need* at least one field in a Sphinx index, which is the
> >> error that happens if you're not including the email_address field.
>
> >> --
> >> Pat
>
> >> On 11/06/2009, at 9:24 PM, Greg Weber wrote:
>
> >>> I am pretty sure now that this is a class loading issue.
>
> >>> On Jun 11, 3:15 pm, Greg Weber <[email protected]> wrote:
> >>>> Yeah typos, I will stop paraphrasing and use my literal code.
>
> >>>> define_index do
> >>>>   indexes email_address
> >>>>   has assoc(:list_memberships).list_id, :as => :list_ids
> >>>> end
>
> >>>> gives the "Cannot automatically map" error
>
> >>>> removing indexes email_address gives warnings and no config sql
>
> >>>> On Jun 11, 1:38 pm, Pat Allan <[email protected]> wrote:
>
> >>>>> Just looking back at earlier emails, your example is as follows:
> >>>>>    define_index
> >>>>>      assoc(:association).column
> >>>>>    end
>
> >>>>> But this doesn't add any fields or attributes. Is it a typo in the
> >>>>> email? Because it should be:
>
> >>>>>    define_index
> >>>>>       indexes assoc(:association).column
> >>>>>       # or
> >>>>>       indexes association.column
> >>>>>    end
>
> >>>>> --
> >>>>> Pat
>
> >>>>> On 11/06/2009, at 4:34 PM, Greg Weber wrote:
>
> >>>>>> I digged in a little more on this problem.
>
> >>>>>> With the simple define_index with only the association ts:conf  
> >>>>>> runs
> >>>>>> without explicit error, but the configuration file has no sql
> >>>>>> query,
> >>>>>> and it prints but with the following warning.
>
> >>>>>> Warning: Error loading /home/greg/ss/trunk/config/../app/models/
> >>>>>> person.rb
>
> >>>>>> The actual error is: "At least one field is necessary for an  
> >>>>>> index"
> >>>>>> By the way I have a simple patch on github to print out the  
> >>>>>> actual
> >>>>>> errorhttp://github.com/gregwebs/thinking-sphinx/commit/de7fa4631e135843bed
> >>>>>> ...
>
> >>>>>> If I have a valid model field before the association, the I get  
> >>>>>> the
> >>>>>> error as described previously.
>
> >>>>>> On Jun 9, 7:28 am, Pat Allan <[email protected]> wrote:
> >>>>>>> Okay, well firstly - alias is required if you're using an
> >>>>>>> association.
>
> >>>>>>> What's the type on the database column you're trying to use?
>
> >>>>>>> --  
> >>>>>>> Pat
>
> >>>>>>> On 09/06/2009, at 10:18 AM, Thibaud Guillaume-Gentil wrote:
>
> >>>>>>>> me too
>
> >>>>>>>> On Jun 9, 4:09 pm, Greg Weber <[email protected]> wrote:
> >>>>>>>>> I got the same result with and without the as alias.
>
> >>>>>>>>> On Jun 8, 9:24 pm, Pat Allan <[email protected]>  
> >>>>>>>>> wrote:
>
> >>>>>>>>>> Are you giving the attribute an alias?
>
> >>>>>>>>>> ie: has relationship.attribute, :as  
> >>>>>>>>>> => :relationship_attribute
>
> >>>>>>>>>> --  
> >>>>>>>>>> Pat
>
> >>>>>>>>>> On 09/06/2009, at 12:20 AM, Greg Weber wrote:
>
> >>>>>>>>>>> thanks, I am going back to the older version for now.
>
> >>>>>>>>>>> The part of my configuration that threw the error was
>
> >>>>>>>>>>> has_many :relationship
> >>>>>>>>>>> define_index { has relationship(:attribute) }
>
> >>>>>>>>>>> On Jun 8, 8:19 pm, Pat Allan <[email protected]>
> >>>>>>>>>>> wrote:
> >>>>>>>>>>>> Hi Greg
>
> >>>>>>>>>>>> I do try to test on older versions of Rails regularly, but
> >>>>>>>>>>>> 1.2.6
> >>>>>>>>>>>> is
> >>>>>>>>>>>> as
> >>>>>>>>>>>> far back as I go. So if possible, I'd recommend updating to
> >>>>>>>>>>>> that.
>
> >>>>>>>>>>>> Besides that, can you outline what your actual define_index
> >>>>>>>>>>>> block is,
> >>>>>>>>>>>> and the associations that you're trying to use?
>
> >>>>>>>>>>>> Also, from memory, I think the assoc method expects a  
> >>>>>>>>>>>> symbol,
> >>>>>>>>>>>> not a
> >>>>>>>>>>>> string.
>
> >>>>>>>>>>>> Cheers
>
> >>>>>>>>>>>> --
> >>>>>>>>>>>> Pat
>
> >>>>>>>>>>>> On 08/06/2009, at 8:02 PM, Greg Weber wrote:
>
> >>>>>>>>>>>>> I have an app with an old version of rails - 1.2.2
>
> >>>>>>>>>>>>> Thinking Sphinx was mostly working, but then I upgraded to
> >>>>>>>>>>>>> the
> >>>>>>>>>>>>> newest
> >>>>>>>>>>>>> version of sphinx, and it broke both has_many and  
> >>>>>>>>>>>>> belongs_to
> >>>>>>>>>>>>> association indexing. It also fails on
> >>>>>>>>>>>>> Rails.configuration, but
> >>>>>>>>>>>>> that
> >>>>>>>>>>>>> was easy enough to work around.
>
> >>>>>>>>>>>>> For any has_many association I get the error
> >>>>>>>>>>>>> "Cannot automatically map attribute #{attribte} in  
> >>>>>>>>>>>>> #{Parent
> >>>>>>>>>>>>> Model} ..."
>
> >>>>>>>>>>>>> It is looking in the parent model, not the association
> >>>>>>>>>>>>> model,
> >>>>>>>>>>>>> which
> >>>>>>>>>>>>> seems to be the problem.
>
> >>>>>>>>>>>>> If I do
>
> >>>>>>>>>>>>> define_index do
> >>>>>>>>>>>>>  assoc("association_name").attribute
> >>>>>>>>>>>>> end
>
> >>>>>>>>>>>>> Then I don't get a failure message, but the generated  
> >>>>>>>>>>>>> sql is
> >>>>>>>>>>>>> still
> >>>>>>>>>>>>> parent_table.attribute with no joining to the association.
>
> >>>>>>>>>>>>> Any help is appreciated. Maybe someone knows the source  
> >>>>>>>>>>>>> can
> >>>>>>>>>>>>> point me
> >>>>>>>>>>>>> to where a patch would need to be applied.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" 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/thinking-sphinx?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to