# Bibtex database design

**URL:** <https://www.ruby-forum.com/t/bibtex-database-design/53025>\
**Category:** Rails\
**Created:** [January 23, 2006, 8:11am UTC](https://www.ruby-forum.com/t/bibtex-database-design/53025 "2006-01-23T08:11:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Horacio\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/97f17d/32.png) [@Horacio\_S](https://www.ruby-forum.com/u/Horacio_S)\
**Post date:** [January 23, 2006, 8:11am UTC](https://www.ruby-forum.com/t/bibtex-database-design/53025/1 "2006-01-23T08:11:42Z")

</div>

I am working a Bibtex database for my school using Rails and I need some  
idea  
on how to manage the bibtex types.

I crated an Author and Publications model and put  
has\_and\_belongs\_to\_many  
relationship between them.

The user model basically is like this:

class User \< ActiveRecord::Base  
has\_and\_belongs\_to\_many :publications

end

The Publication model has all the Bibtex fields and I use STI for  
managing the  
bibtex types like:

class Publication \< ActiveRecord::Base  
has\_and\_belongs\_to\_many :users  
end

class Article \< Publication  
# An article from a journal or magazine. Required fields:  
author,  
title, journal, year.  
# Optional fields: volume, number, pages, month, note.  
validates\_presence\_of :title, :journal, :year  
end  
end

class Book \< Publication  
# A book with an explicit publisher. Required fields: author or  
# editor, title, publisher, year.  
# Optional fields: volume or number, series, address, edition,  
month,  
# note.  
validates\_presence\_of :title, :publisher, :year  
end

class Booklet \< Publication  
# A work that is printed and bound, but without a named  
publisher or  
sponsoring institution.  
# Required field: title. Optional fields: author, howpublished,  
address, month, year, note.  
validates\_presence\_of :title  
end  
class InBook \< Publication  
# A part of a book, which may be a chapter (or section or  
whatever)  
and/or a range of pages.  
# Required fields: author or editor, title, chapter and/or  
pages,  
publisher, year.  
# Optional fields: volume or number, series, type, address,  
edition,  
month, note.  
validates\_presence\_of :title, :chapter, :pages, :publisher,  
:year  
end

class InCollection \< Publication  
# A part of a book having its own title. Required fields:  
author,  
title, booktitle, publisher, year.  
# Optional fields: editor, volume or number, series, type,  
chapter,  
pages, address, edition, month, note.  
validates\_presence\_of :title, :booktitle, :publisher, :year  
end

class InProceedings \< Publication  
# An article in a conference proceedings. Required fields:  
author,  
title, booktitle, year.  
# Optional fields: editor, volume or number, series, pages,  
address,  
month, organization, publisher, note.  
validates\_presence\_of :title, :booktitle, :year  
end

Now this is ok but in the view part I want to create a form that would  
display  
certain fields based on the publication type. For example Article has  
some  
required, optional and ignored fields. I want the view (Create/Edit) to  
show  
only those attributes relevant to a publication class.

I tried overriding the content\_columns but in console I get a stack too  
deep  
error or segfaults sometimes.

I tried this

class Article \< Publication  
validates\_presence\_of :title, :journal, :year

```
    def self.content_columns
            return Article.content_columns.delete_if {|c|

```

[“publisher”].include?(c.name) }  
end  
end

Any ideas on how to do this without having to create a different view  
for each  
publication type?

regards,  
Horacio

---

<div class="post-metadata">

**Author:** ![Horacio\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/97f17d/32.png) [@Horacio\_S](https://www.ruby-forum.com/u/Horacio_S)\
**Post date:** [January 23, 2006, 2:22pm UTC](https://www.ruby-forum.com/t/bibtex-database-design/53025/2 "2006-01-23T14:22:06Z")

</div>

Horacio S. wrote:

> Now this is ok but in the view part I want to create a form that would  
> display  
> certain fields based on the publication type. For example Article has  
> some  
> required, optional and ignored fields. I want the view (Create/Edit) to  
> show  
> only those attributes relevant to a publication class.
> 
> I tried overriding the content\_columns but in console I get a stack too  
> deep  
> error or segfaults sometimes.
> 
> I tried this
> 
> class Article \< Publication  
> validates\_presence\_of :title, :journal, :year
> 
> ```
> def self.content_columns
> return Article.content_columns.delete_if {|c|
> 
> ```
> 
> [“publisher”].include?(c.name) }  
> end  
> end
> 
> Any ideas on how to do this without having to create a different view  
> for each  
> publication type?
> 
> regards,  
> Horacio

You can do some if…then (or case…when) conditionals in the view which  
depends on the publication type.

you can probably put in things like…

\<%= text\_field(‘name’,‘id’) if @object.isa? Book -%\>

\_Kevin

---

<div class="post-metadata">

**Author:** ![Horacio\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/97f17d/32.png) [@Horacio\_S](https://www.ruby-forum.com/u/Horacio_S)\
**Post date:** [January 23, 2006, 4:35pm UTC](https://www.ruby-forum.com/t/bibtex-database-design/53025/3 "2006-01-23T16:35:09Z")

</div>

Horacio S. \<hsanson@…\> writes:

> I am working a Bibtex database for my school using Rails and I need some idea  
> on how to manage the bibtex types.
> 
> I crated an Author and Publications model and put has\_and\_belongs\_to\_many  
> relationship between them.

Since I think about this issue a lot, I’d like to prompt you to consider  
whether you really want to base this on BibTeX, which has a poor  
data model.

So rather than Author, how about Agent, and then have two  
subclasses: Person and Organization.

You then relate those agents to Reference objects (which can be more  
than just publications) through a HABTM join.

The reason is that I might be an author of one work, an editor of  
another, and a translator of still another. Likewise, there are  
organizational authors, and organizations also have other roles  
(like publishers).

Other important classes and subclasses:

Event  
Conference \< Event  
Hearing \< Event  
Publisher \< Organization  
Collection  
Series \< Collection  
Periodical \< Collection

So you can then think about relations like:

[Reference with type of “paper”]  
authored by --\> [Person “Jane Doe”]  
presented at --\> [Conference “ABC Conference”]  
published in --\> [Proceeedings “Proceedings of ABC Conference”]  
published by --\> [Publisher “XYZ Publishing”]

I tend to think that parts (article, chapters, etc.) might well be  
stored in  
the same table, but am not sure. I think reference types probably ought  
to just be stored in a separate table for flexibility’s sake.

Just a thought …

Bruce

---

<div class="post-metadata">

**Author:** ![Horacio\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/97f17d/32.png) [@Horacio\_S](https://www.ruby-forum.com/u/Horacio_S)\
**Post date:** [January 24, 2006, 4:43am UTC](https://www.ruby-forum.com/t/bibtex-database-design/53025/4 "2006-01-24T04:43:17Z")

</div>

Thanks, I would really like to use a model different from the Bibtex  
one.  
Unfortunately the database is a legacy one in Bibtex format and has all  
publications of my school since 1977 (quite a lot).

Changing the model may be a real challenge (Migrations maybe?). Anyway I  
like  
this idea of Events, Agents and Organizations… I will look into it.

For now I will simply create a single View that displays the fields  
depending  
on the Class (subclass).

Horacio

Tuesday 24 January 2006 00:17ã?Bruce D’Arcus ã?ã??ã¯æ?¸ãã¾ã?ã?:

---

<div class="post-metadata">

**Author:** ![Horacio\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/97f17d/32.png) [@Horacio\_S](https://www.ruby-forum.com/u/Horacio_S)\
**Post date:** [February 13, 2006, 8:50pm UTC](https://www.ruby-forum.com/t/bibtex-database-design/53025/5 "2006-02-13T20:50:17Z")

</div>

maybe you could use yaml to store it all in one coumn.  
One filld could be the type - inproceedings/artcle/… and the rest of  
the  
fields would just be in the yaml. then you could construct the right  
kind  
of object
