having an integer matrix inside model

Hey,

Is there any way I can have a model to store an N by N integer matrix? Something that would be able to keep record of rows and seats.

n[i][j] = 1 if the seat is empty n[i][j] = 2 if the seat is reserved

Possibly Auditorium has_many Rows Row has_many Seats Seat belongs_to Row Row belongs_to Auditorium

Colin

too much complex:)

is good enough to keep only row#nr and seat#nr, eg

table seats contains:   id   seat_number   row_number

is much faster to search/update

tom

Colin Law wrote:

You might find the arrangement using relationships is actually significantly simpler to develop, and with a maximum of a few thousand seats (presumably) you are unlikely to notice any difference in lookup.

The fact that you talk about rows suggests that this is a concept that is part of your mental image of the problem, it is often best to map your mental image of the problem into the application, it makes it a better representation of the real world, which may be much more important than a few milliseconds of database lookup.

For example, do you wish to keep the number of seats in each row somewhere? Put it in the rows table.

Colin

I would still go for Models Room, Row and Seat with the relationships as above, it seems like a better mapping of the problem. But if your solution is a better mapping for the way you see the problem then that is the best solution for you.

Consider how to access a particular seat. In the Room, Row, Seat solution if you have the record for a particular room then value for seat 5 on row 3 would be referenced by room.row[3].seat[5].value (assuming zero based indexing, you might have to add one to the indexes for real world mapping) How would this be achieved with the Room and RoomPlan models?

Colin

Colin Law wrote: [...]

if you have the record for a particular room then value for seat 5 on row 3 would be referenced by room.row[3].seat[5].value (assuming zero based indexing, you might have to add one to the indexes for real world mapping) How would this be achieved with the Room and RoomPlan models?

Colin

Well, another way to do it might be to simply have a 2D array serialized to YAML. That gives the addressability without the join overhead. I tend to agree with you, though: a separate Seat table (probably not a Row table, though) would be good -- it would allow the storage of more than 1 byte of data for each seat...

Best,