Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Using a model without a table
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
JoeLoui  
View profile  
 More options Oct 9 2012, 5:07 pm
From: JoeLoui <joe.escala...@gmail.com>
Date: Tue, 9 Oct 2012 14:07:24 -0700 (PDT)
Local: Tues, Oct 9 2012 5:07 pm
Subject: Using a model without a table
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?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeremy Evans  
View profile  
 More options Oct 9 2012, 6:06 pm
From: Jeremy Evans <jeremyeva...@gmail.com>
Date: Tue, 9 Oct 2012 15:06:49 -0700 (PDT)
Local: Tues, Oct 9 2012 6:06 pm
Subject: Re: Using a model without a table

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
JoeLoui  
View profile  
 More options Oct 10 2012, 4:58 pm
From: JoeLoui <joe.escala...@gmail.com>
Date: Wed, 10 Oct 2012 17:57:40 -0300
Local: Wed, Oct 10 2012 4:57 pm
Subject: Re: Using a model without a table

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 must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeremy Evans  
View profile  
 More options Oct 10 2012, 5:24 pm
From: Jeremy Evans <jeremyeva...@gmail.com>
Date: Wed, 10 Oct 2012 14:24:10 -0700 (PDT)
Local: Wed, Oct 10 2012 5:24 pm
Subject: Re: Using a model without a table

On Wednesday, October 10, 2012 10:58:02 PM UTC+2, JoeLoui wrote:

> 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?

You can use a plain ruby module with an included/extended hook or plugin to
share code between models in this way.  See https://gist.github.com/3868477
for an example using a plugin.

Jeremy


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
JoeLoui  
View profile  
 More options Oct 10 2012, 7:37 pm
From: JoeLoui <joe.escala...@gmail.com>
Date: Wed, 10 Oct 2012 20:37:31 -0300
Local: Wed, Oct 10 2012 7:37 pm
Subject: Re: Using a model without a table

On Wed, Oct 10, 2012 at 6:24 PM, Jeremy Evans <jeremyeva...@gmail.com>wrote:

That's a great idea! In the beginning I thought about using a module too,
but I discarded the idea because I thought that Sequel could have something
like an interface, but now I realize that this is Ruby and not Java and the
modules are powerful and flexible!

Thank you!
Joe


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »