# Problem with set\_table\_name and custom method in model

**URL:** <https://www.ruby-forum.com/t/problem-with-set-table-name-and-custom-method-in-model/148328>\
**Category:** Rails\
**Created:** [September 11, 2008, 7:15pm UTC](https://www.ruby-forum.com/t/problem-with-set-table-name-and-custom-method-in-model/148328 "2008-09-11T19:15:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rgagnon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e95f7d/32.png) [@rgagnon](https://www.ruby-forum.com/u/rgagnon)\
**Post date:** [September 11, 2008, 7:15pm UTC](https://www.ruby-forum.com/t/problem-with-set-table-name-and-custom-method-in-model/148328/1 "2008-09-11T19:15:45Z")

</div>

Hi,

When I try to run this command I got a table does not exist.

> > Vehicule.get\_vehicule(123,1123)

class Vehicule \< ActiveRecord::Base

set\_table\_name “table\_a”

def self.get\_vehicule( inte\_no, poas\_no)  
find\_by\_inte\_no\_and\_poas\_no( inte\_no, poas\_no)  
end  
end

It looks like if you have a custom method in your model, the  
“set\_table\_name” is not taken as the real table name. As soon I rename  
my model the name of the table(which is not what I want) the  
get\_vehicule worked.

I’m on Rails edge.

RÃ©mi

---

<div class="post-metadata">

**Author:** ![rgagnon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e95f7d/32.png) [@rgagnon](https://www.ruby-forum.com/u/rgagnon)\
**Post date:** [September 12, 2008, 3:58am UTC](https://www.ruby-forum.com/t/problem-with-set-table-name-and-custom-method-in-model/148328/2 "2008-09-12T03:58:59Z")

</div>

I recall having a similar problem. I believe I got around it by  
overriding the table\_name method on the class, e.g.:

class Vehicule \< ActiveRecord::Base

def self.table\_name  
“table\_a”  
end

end

Christian

On Thu, Sep 11, 2008 at 7:15 PM, Rémi Gagnon

---

<div class="post-metadata">

**Author:** ![rgagnon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e95f7d/32.png) [@rgagnon](https://www.ruby-forum.com/u/rgagnon)\
**Post date:** [September 17, 2008, 2:34pm UTC](https://www.ruby-forum.com/t/problem-with-set-table-name-and-custom-method-in-model/148328/3 "2008-09-17T14:34:54Z")

</div>

Christian RishÃ¸j wrote:

> I recall having a similar problem. I believe I got around it by  
> overriding the table\_name method on the class, e.g.:
> 
> class Vehicule \< ActiveRecord::Base
> 
> def self.table\_name  
> “table\_a”  
> end
> 
> end
> 
> Christian
> 
> On Thu, Sep 11, 2008 at 7:15 PM, Rï¿½mi Gagnon

Thanks for the response. But it does not seem to work. I have the same  
problem.

any other ideas?

---

<div class="post-metadata">

**Author:** ![rgagnon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e95f7d/32.png) [@rgagnon](https://www.ruby-forum.com/u/rgagnon)\
**Post date:** [September 18, 2008, 11:26pm UTC](https://www.ruby-forum.com/t/problem-with-set-table-name-and-custom-method-in-model/148328/4 "2008-09-18T23:26:00Z")

</div>

Just a guess but maybe it will work if instead of self. you use  
Vehicle. when defining the method:

Vehicule.get\_vehicule(…)

Pepe

On Sep 17, 8:34 am, Rémi Gagnon [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![rgagnon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e95f7d/32.png) [@rgagnon](https://www.ruby-forum.com/u/rgagnon)\
**Post date:** [September 23, 2008, 5:52pm UTC](https://www.ruby-forum.com/t/problem-with-set-table-name-and-custom-method-in-model/148328/5 "2008-09-23T17:52:14Z")

</div>

pepe wrote:

> Just a guess but maybe it will work if instead of self. you use  
> Vehicle. when defining the method:
> 
> Vehicule.get\_vehicule(…)
> 
> Pepe
> 
> On Sep 17, 8:34ï¿½am, Rï¿½mi Gagnon [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

I found the problem.

When you do a set\_table\_name you have to put the name with the right  
case. At least in oracle cause it translates it like :

‘select \* from “table\_a”’

and it should be like this

‘select \* from “TABLE\_A”’
