How to implement has_many :through relationships with Mongoid and mongodb?

Mongoid doesn’t have has_many :through or an equivalent feature. It would not be so useful with MongoDB because it does not support join queries so even if you could reference a related collection via another it would still require multiple queries. https://github.com/mongoid/mongoid/issues/544 Normally if you have a many-many relationship in a RDBMS you would model … Read more

What is the most efficient way to store tags in a database?

One item is going to have many tags. And one tag will belong to many items. This implies to me that you’ll quite possibly need an intermediary table to overcome the many-to-many obstacle. Something like: Table: Items Columns: Item_ID, Item_Title, Content Table: Tags Columns: Tag_ID, Tag_Title Table: Items_Tags Columns: Item_ID, Tag_ID It might be that … Read more

What should I name a table that maps two tables together? [closed]

There are only two hard things in Computer Science: cache invalidation and naming things— Phil Karlton Coming up with a good name for a table that represents a many-to-many relationship makes the relationship easier to read and understand. Sometimes finding a great name is not trivial but usually it is worth to spend some time … Read more

What’s the longest possible worldwide phone number I should consider in SQL varchar(length) for phone

Assuming you don’t store things like the ‘+’, ‘()’, ‘-‘, spaces and what-have-yous (and why would you, they are presentational concerns which would vary based on local customs and the network distributions anyways), the ITU-T recommendation E.164 for the international telephone network (which most national networks are connected via) specifies that the entire number (including … Read more

What’s the best way to model recurring events in a calendar application? [closed]

I would use a ‘link’ concept for all future recurring events. They are dynamically displayed in the calendar and link back to a single reference object. When events have taken place the link is broken and the event becomes a standalone instance. If you attempt to edit a recurring event then prompt to change all … Read more

Recommended SQL database design for tags or tagging [closed]

Three tables (one for storing all items, one for all tags, and one for the relation between the two), properly indexed, with foreign keys set running on a proper database, should work well and scale properly. Table: Item Columns: ItemID, Title, Content Table: Tag Columns: TagID, Title Table: ItemTag Columns: ItemID, TagID

What’s the difference between identifying and non-identifying relationships?

An identifying relationship is when the existence of a row in a child table depends on a row in a parent table. This may be confusing because it’s common practice these days to create a pseudokey for a child table, but not make the foreign key to the parent part of the child’s primary key. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)