On Tue, Oct 9, 2012 at 7:06 PM, Jeremy Evans <[email protected]> wrote:

> On Tuesday, October 9, 2012 11:07:24 PM UTC+2, JoeLoui wrote:
>>
>> Hi, I stuck trying to find how to solve this: I have a 2 models (Bar1,
>> Bar2) which shares similar behaviour but different tables and because
>> of that exists a Foo class which is a Sequel model (it's a Sequel
>> model because I don't want to repeat validations and callbacks) from
>> where Bar1 and Bar2 inheritates some behaviour.
>>
>> I'm using set_dataset to tell Sequel what table to use for Bar1 and
>> Bar2, but how can I tell to Sequel that Foo doesn't have a table?
>>
>> In the IRC channel Jeremy gave me a hint, he told me I can use an
>> anonymous class like this:
>>
>> Foo = Class.new(Sequel::Model)
>>
>> I try to use this in my code like this:
>>
>> Foo = Class.new(Sequel::Model)
>> class Foo
>>   ...
>> end
>>
>> But I get this error: No dataset associated with Foo
>>
>> Then I tried the following
>>
>> Foo = Class.new(Sequel::Model) do
>>   ...
>> end
>>
>> And this time I get this: No dataset associated with #<Class:
>> 0x00000002d54830>
>>
>> So I don't know how to work this out... Any hints?
>>
>
> If you get an error, always provide the full backtrace and full code, and
> if it is an SQL error, an SQL log, otherwise it's hard to determine where
> the actual problem is.  My guess is the problem is in some code that you
> did not post here.  Most likely you are doing something with Foo that
> requires a dataset, and you haven't given it one.  You shouldn't be doing
> anything that requires a dataset if you are trying to use it as an abstract
> base class.
>
> Jeremy
>
> Sorry for not being more specific, I tried to be general but I realized
that is difficulting the problem understading. Here it is the
gist<https://gist.github.com/3868059>with the full backtraces for both
examples.

In my Foo class I'm using something like this<https://gist.github.com/3868152>.
The reason I'm doing this it's because I don't want to repeat this code in
Bar1 and Bar2, and it's worth to mention that Bar1 and Bar2 each has
differents columns but shares the relationship with user (and the
callbacks). I supossed that I could use a sequel model as a some kind of
interface in order to DRYup the code, besides I will never need instantiate
Foo for any reason, but it would be handy sometimes not to care having a
Foo object whether is Bar1 or Bar2. As you correctly guessed I think I'm
using methods which needs a dataset, in what other ways can I make this?

Joe

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-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/sequel-talk?hl=en.

Reply via email to