<commit_before>using System;
using System.Reflection;
using FluentNHibernate.Conventions.AcceptanceCriteria;
using FluentNHibernate.Conventions.Instances;
using FluentNHibernate.Conventions.Inspections;

namespace FluentNHibernate.Conventions
{
    public abstract class ForeignKeyConvention
        : IReferenceConvention, IConventionAcceptance<IManyToOneInspector>,
          IHasManyConvention, IConventionAcceptance<IOneToManyCollectionInspector>,
          IHasManyToManyConvention, IConventionAcceptance<IManyToManyCollectionInspector>
    {
        protected abstract string GetKeyName(PropertyInfo property, Type type);

        public void Accept(IAcceptanceCriteria<IManyToOneInspector> acceptance)
        {
            acceptance.Expect(x => x.Columns.IsEmpty());
        }

        public void Apply(IManyToOneInstance instance)
        {
            var columnName = GetKeyName(instance.Property, instance.Class.GetUnderlyingSystemType());

            instance.Column(columnName);
        }

        public void Accept(IAcceptanceCriteria<IOneToManyCollectionInspector> acceptance)
        {
            acceptance.Expect(x => x.Key.Columns.IsEmpty());
        }

        public void Apply(IOneToManyCollectionInstance instance)
        {
            var columnName = GetKeyName(null, instance.EntityType);

            instance.Key.Column(columnName);
        }

        public void Accept(IAcceptanceCriteria<IManyToManyCollectionInspector> acceptance)
        {
            acceptance.Expect(x => x.Key.Columns.IsEmpty() || x.Relationship.Columns.IsEmpty());
        }

        public void Apply(IManyToManyCollectionInstance instance)
        {
            var keyColumn = GetKeyName(null, instance.EntityType);
            var childColumn = GetKeyName(null, instance.ChildType);

            if (instance.Key.Columns.IsEmpty())
                instance.Key.Column(keyColumn);

            if (instance.Relationship.Columns.IsEmpty())
                instance.Relationship.Column(childColumn);
        }
    }
}<commit_msg>Removed acceptance from ForeignKeyConvention as it's not needed anymore. Also added in support for joined-subclass foreign-keys.<commit_after>using System;
using System.Reflection;
using FluentNHibernate.Conventions.AcceptanceCriteria;
using FluentNHibernate.Conventions.Instances;
using FluentNHibernate.Conventions.Inspections;

namespace FluentNHibernate.Conventions
{
    public abstract class ForeignKeyConvention
        : IReferenceConvention, IHasManyConvention, IHasManyToManyConvention, IJoinedSubclassConvention
    {
        protected abstract string GetKeyName(PropertyInfo property, Type type);

        public void Apply(IManyToOneInstance instance)
        {
            var columnName = GetKeyName(instance.Property, instance.Class.GetUnderlyingSystemType());

            instance.Column(columnName);
        }

        public void Apply(IOneToManyCollectionInstance instance)
        {
            var columnName = GetKeyName(null, instance.EntityType);

            instance.Key.Column(columnName);
        }

        public void Apply(IManyToManyCollectionInstance instance)
        {
            var keyColumn = GetKeyName(null, instance.EntityType);
            var childColumn = GetKeyName(null, instance.ChildType);

            if (instance.Key.Columns.IsEmpty())
                instance.Key.Column(keyColumn);

            if (instance.Relationship.Columns.IsEmpty())
                instance.Relationship.Column(childColumn);
        }

        public void Apply(IJoinedSubclassInstance instance)
        {
            var columnName = GetKeyName(null, instance.Type);
            
            instance.Key.Column(columnName);
        }
    }
}
{'fraction_non_alphanumeric': 0.07725437415881561, 'fraction_numerical': 0.0, 'mean_word_length': 2.899265477439664, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6076847', 'n_tokens_mistral': 968, 'n_tokens_neox': 930, 'n_words': 171}