logo
down
shadow

Database organization for separating two different types of the same model


Database organization for separating two different types of the same model

By : Tuan Le
Date : November 17 2020, 04:28 AM
fixed the issue. Will look into that further So I want my User model to have_many Skills. I want there to be two different categories for the skills: a wanted skill, and a possessed skill. , You can use single table inheritance
code :
class Skill < ActiveRecord::Base
end

class WantedSkill < Skill
   belongs_to :user
end

class PossessesSkill < Skill
  belongs_to :user
end
WantedSkill.create(:name => "html")
WantedSkill.where(:name => "html").first
class User < ActiveRecord::Base
   has_many :wanted_skills
   has_many :possessed_skills
end


Share : facebook icon twitter icon
model classes in a database with my own enum types

model classes in a database with my own enum types


By : aconpa aconpa
Date : March 29 2020, 07:55 AM
should help you out I prefer to statically map my enums in my program to a lookup table in my database. I rarely actually use the lookup table to do a join. As an example I might have the following tables:
code :
Gender
GenderID  Name
1         Male
2         Female

Accounts
AccountID  GenderID  FirstName  LastName
1          1         Andrew     Siemer
2          2         Jessica    Siemer
public enum Gender
{
    Male = 1,
    Female = 2
}
int genderValue = (int)Enum.Parse(typeof(Gender), Gender.Male));
How to model several tournaments / brackets types into a SQL database?

How to model several tournaments / brackets types into a SQL database?


By : Alex Aminoff
Date : March 29 2020, 07:55 AM
should help you out I can understand why you're struggling with modeling this. One of the key reasons why this is difficult is because of the object relational impendance-mismatch. While I am a huge fan of SQL and it is an incredibly powerful way of being able to organize data, one of its downfalls - and why NoSQL exists - is because SQL is different from Object Oriented Programming. When you describe leagues, with different matches, it's pretty easy to picture this in object form: A Match object is extended by League_Match, Round_Match, Knockout_Match, etc. Each of these Match objects contains two Team objects. Team can be extended to Winner and Loser...
But this is not how SQL databases work.
code :
[
    {
        name: "team A",
        schedule: [
            {
                date: "11/1/15",
                vs: "team B",
                score1: 2,
                score2: 4
             },
             {
                date: "11/15/15",
                vs: "team C",
             }
        ]
    }
],
[
   //more teams
]
Tournament
- id (int, PK)
- tournament_name
- tournament_type

Team
- id (int, PK)
- team_name (varchar, not null)
# Any other team columns you want.

Match
- id (int, PK, autoincrement)
- date (int)
- team_a_score (int, null)
- team_b_score (int, null)
- status (either future, past, or live)
- tournament_id (int, Foreign Key)

Match_Round
- match_id (int, not null, foreign key to match.id)
- team_a_id (int, not null, foreign key to team.id)
- team_b_id (int, not null, foreign key to team.id)

Match_Knockout
- match_id (int, not null, foreign key to match.id)
- winner__a_of (match_id, not null, foreign key to match.id)
- winner_b_of (match_id, not null, foreign key to match.id)
Sequelize Issue By Separating Model Logic from Model Configuration

Sequelize Issue By Separating Model Logic from Model Configuration


By : Gerardo Filho
Date : March 29 2020, 07:55 AM
hop of those help? I think problem in your post method, but structure is really confusing so can you do this
models/index.js
code :
"use strict";

var fs        = require("fs");
var path      = require("path");
var Sequelize = require("sequelize");
var env       = process.env.NODE_ENV || "development";
var config    = require(__dirname + '/../config/config.json')[env];
var sequelize = new Sequelize(config.database, config.username, config.password, config);
var db        = {};

fs
  .readdirSync(__dirname)
  .filter(function(file) {
    return (file.indexOf(".") !== 0) && (file !== "index.js");
  })
  .forEach(function(file) {
    var model = sequelize.import(path.join(__dirname, file));
    db[model.name] = model;
  });

Object.keys(db).forEach(function(modelName) {
  if ("associate" in db[modelName]) {
    db[modelName].associate(db);
  }
});
db.sequelize = sequelize;
db.Sequelize = Sequelize;

module.exports = db;
"use strict";

module.exports = function(sequelize, DataTypes) {

var Ann = sequelize.define('ann', {
    ann_id: {
        type: DataTypes.INTEGER,
        primaryKey: true
    },
    ann_date: DataTypes.DATE,
}, {
    freezeTableName: true
});
    return Ann;
}
var express = require('express');
var appRoutes   = express.Router();
var models = require('../models');

appRoutes.route('/') 

    .get(function(req, res){
        res.send('ok');
    })

    .post(function(req, res){

      models.ann
      .build({ ann_id: 55, ann_date: new Date() })
      .save()
      .then(function(anotherTask) {
        res.send("POST OK"); 
      }).catch(function(error) {
        res.send(error);
      })

    });

module.exports = appRoutes;
JSONAPI Active Model Serializer not separating model relationships to it's own object as spec describes

JSONAPI Active Model Serializer not separating model relationships to it's own object as spec describes


By : tina
Date : March 29 2020, 07:55 AM
will be helpful for those in need I was missing relationships in my serializer!
Also answered in x post
How is Change Tracking an issue when separating the Domain Model and Persistence Model?

How is Change Tracking an issue when separating the Domain Model and Persistence Model?


By : Camelo
Date : March 29 2020, 07:55 AM
this will help Most of the details in answer from @MikeSW are correct; I only disagree with change tracking. My answer is more in terms of NHibernate than DDD.
Yes, change tracking will be an issue but it depends on how the ISession is managed. Further, not only change tracking, it will also affect other features of NHibernate like Session Level Cache, Lazy Loading etc.
code :
public TicketEntity GetTicket(int ticketId)
{
    Ticket persistanceModel = this.ticketsRepository.GetById(ticketId);
    TicketEntity domainModel = new TicketEntity(
        persistanceModel.Id,
        persistanceModel.Cost,
        persistanceModel.ExpiryDate);

    return domainModel;
}

public void SaveTicket(TicketEntity ticketEntity)
{
    Ticket ticket = //Here, you have to map TicketEntity to Ticket
    this.ticketsRepository.Save(ticket);
}
TicketEntity ticketEntity = applicationService.GetTicket(1);
ticketEntity.Cost = .....
.....
.....
applicationService.SaveTicket(ticketEntity);
public Ticket GetTicket(int ticketId)
{
    return this.ticketsRepository.GetById(ticketId);
}
Ticket ticket = applicationService.GetTicket(1);
ticket.Cost = .....
.....
.....
Related Posts Related Posts :
  • Page loads unnecessary queries Ruby On Rails
  • Why "bundle install" try to install outdated version of gems?
  • Rails - Customize model validation error messages but without a database
  • When to switch from cucumber to rspec in the BDD cycle for a login procedure
  • Multipart response for web service
  • How to hide Add new option in Rails Admin
  • Override CollectionProxy find method
  • Rails 4 simple_form has_many through check boxes not saving
  • ruby on rails authentication using devise gem
  • Rails iteration over arrays and hashes
  • Creating inline date_select dropdowns using simple_form and zurb foundation
  • NameError in SongsController#index uninitialized constant Song::FriendlyId
  • Rails how to improve if record exists?
  • omniauth custom request phase form
  • Rails 5 - Saving the absolute current url via a button to a cookie?
  • How can / should I override the `build` method for a my model?
  • Install Rails Failed on OSX 10.8.4
  • ruby on rails - undefined method valid?
  • Users Registration on POST
  • Rails application variables in carrierwave store_dir
  • How to customize simple_form for json nested hash
  • Couldn't find file 'jquery', Sprockets::FileNotFound in StaticPages#home error
  • How should I use the alias_method_chain for the build method?
  • how to create two custom registration forms in devise?
  • Rails 4 link_to Destroy not working in Getting Started tutorial
  • How does ruby on rails dynamically define `find_by_id`, `find_by_name` methods?
  • JBuilder dynamic keys for model attributes
  • `initialize': No such file or directory - getaddrinfo (Errno::ENOENT) when Rails new app
  • What is the Ruby equivalent of Node.js' socket.io?
  • Where rails store standard helpers?
  • how to check expected result matches any of give values in rspec?
  • Form submission to create multiple objects
  • Simple Twitter Login with Rails and Email confirmation
  • Where should helpful functions for my controller go in Rails?
  • Using session variable in the Model or the other way
  • Why can't I have ruby code and comments in Embedded Ruby?
  • Rails: How can I make an object available in all views?
  • Cannot enter simply form information into SQLite DB (Rails)
  • Rails - Retain form values on failed submission. Getting "First argument in form cannot contain nil or be empty&quo
  • How to handle STI and build related models automatically?
  • Suppress an error when saving a record in Rails
  • Rails AJAX reload the page. Why?
  • How to pass user attributes to action mailer
  • Custom Validator to Prevent an appointment from being scheduled too early in day?
  • Postgres Enable TCP/IP Connection
  • How do I avoid the circular argument reference warning in activesupport
  • Unable to push to heroku master because of rails/spring version error
  • deep nested routes in rails
  • Best approach to Users Profile Images in Rails App
  • RailsInstaller: Can I maintain the gem fold when re-installing a new version?
  • couldn't find file 'jquery-ui' i get this error even after having this file in my application.js
  • Ruby regex to split user and date text input
  • Tool like BetterErrors for JRuby?
  • redirect_to in action destroy ruby on rails
  • Where are the I18n.t link and reference paths?
  • Sending emails to multiple recipients in rails app
  • Rails, Devise, Sign up = write name in other Database
  • pass custom attribute on rspec factory_girl controller test
  • rails generate uses wrong version of Ruby
  • Duplicate Requests from a Browser
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org