altrabio/CITIEsForRAILS — Issue #8: Failure to find instances of subclasses
Author: grep-awesome
Created: 2012-01-04 04:42:36+00:00
State: open

# Summary

When an instance of a subclass is created and none of the fields specific to that class are entered, the object cannot be queried

## Situations where this is a problem

Some subclasses may only contain foreign key fields. For example, the Parent class in the prerequisites section could only contain the children field. This bug prevents the Parent class from being a persistable object.

# Prerequisites

Suppose the following classes

* Person
* name (string)
* birthday (datetime)
* Parent (extends Person)
* children (foreign key)
* can_yodel (int)
* Child (extends Person)
* parents (foreign key)

# Failure use-case

If you create a new parent object, but fail to set any attributes specific to the parent table, then It will not show up when queried

```ruby
parent = Parent.new
parent.name = 'Shepherd Book'
parent.birthday = Time.now
parent.save
```
When you try to query for this item, it is inaccessible

```ruby
Parent.where(:name => 'Shepherd Book')
```
returns

=> []

# Working use-case

When you create an instance of a subclass and use one or more of the fields specific to that subclass you can query for it

```ruby
parent = Parent.new
parent.name = 'Shepherd Book'
parent.birthday = Time.now
parent.can_yodel = 1
parent.save
```

returns

=> [#