Question: I have two models:

User

```
has_one :email

```

Email

```
belongs_to :user

```

I put the email\_id foreign key (NOT NULL) inside users table.
Now I'm trying to save it in the following way:

```
@email = Email.new(params[:email])
@email.user = User.new(params[:user])
@email.save

```

This raises a db exception, because the foreign key constraint is not met (NULL is inserted into email\_id). How can I elegantly solve this or is my data modeling wrong?

Answer: 
Just declare somewhere these static functions:

```
public delegate object AnonymousDelegate();

public static object GetDelegateResult(AnonymousDelegate function)
{
    return function.Invoke();
}

```

And anywhere use it as you want like this:

```
object item = GetDelegateResult(delegate { return "TEST"; });

```

or even like this

```
object item = ((AnonymousDelegate)delegate { return "TEST"; }).Invoke();

```
```
using System;

public delegate int ReturnedDelegate(string s);

class AnonymousDelegate
{
    static void Main()
    {
        ReturnedDelegate len = delegate(string s)
        {
            return s.Length;
        };
        Console.WriteLine(len("hello world"));
    }
}

```