Yes Marnen, I agree; it’s not really useful. But I prefer to do this
rather then having a table with only 1 row.
And you can.
That’s why I would like to
get a singleton model with a static data (and always the same id for
associations with other models).
Why do you need an ID? Again, please explain in more detail what you
are trying to do. has_many and belongs_to are only useful when dealing
with SQL, as I see it. Otherwise, you don’t need them; a non-SQL
approach could be as simple as
class Book < ActiveModel
attr_accessor :pages
def initialize @pages = []
end
end
book = Book.new
…and then book.pages, book.pages.count, and book.pages << Page.new all
work as expected. That’s just the way OO development works.
has_many and belongs_to are a hack to make SQL databases feel more OO.
You don’t need them if there’s no SQL.
Yes Marnen, I agree; it’s not really useful. But I prefer to do this
rather then having a table with only 1 row. That’s why I would like to
get a singleton model with a static data (and always the same id for
associations with other models).
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.