标签: self-reference

奎因是什么意思?

所以我刚刚在维基百科上看到了Quine一词,但无法弄清楚它到底是什么意思。我对此非常困惑。它有任何实际用途吗?

language-agnostic definition quine self-reference

6
推荐指数
2
解决办法
505
查看次数

Rails自我引用has_many通过自定义连接表命名

围绕以下情况我有些麻烦.

我正在尝试创建一个树结构,在那里我将能够为节点之间的连接提供自定义名称.

所以我想拥有Node和Relation模型.每

Node 
 has_many :relations
Run Code Online (Sandbox Code Playgroud)

Relation 
 has_many :nodes
Run Code Online (Sandbox Code Playgroud)

节点可以是父母或孩子..到目前为止一切都方便,还有吨的例子展示了如何做一个自我指涉的has_many表...问题是,我希望能够给予名称的关系,以便我可以做类似的事情:

relation1 = node1.relations.create(:name => "relation_name", :child => node2)
Run Code Online (Sandbox Code Playgroud)

并在结果得到类似的东西:

relation1.name == "relation_name"
relation1.parent == node1
relation1.child == node2
Run Code Online (Sandbox Code Playgroud)

所有的创作都发生在模型中,如果重要的话,这个活动并没有真正暴露给用户.谢谢!

EDIT2:现在它是如何工作的:

class Node < ActiveRecord::Base
  belongs_to :sentence

  has_one :parent_relation, :foreign_key => "child_id", :class_name => "Relation"
  has_many :child_relations, :foreign_key => "parent_id", :class_name => "Relation"

  has_one :parent, :through => :parent_relation
  has_many :children,  :through => :child_relations, :source => :child

  has_many :relations, :foreign_key => "child_id"
  has_many :relations, :foreign_key => "parent_id"

class Relation < ActiveRecord::Base …
Run Code Online (Sandbox Code Playgroud)

model relational-database has-many self-reference ruby-on-rails-3

5
推荐指数
1
解决办法
3361
查看次数

接口中的自引用

好的,这就是我想做的.

Class Container<T>
{
    T contained;
    public void ContainObject(T obj)
    {
        contained = obj;
        if(/*Magical Code That Detects If T Implemtns IContainableObject*/)
        {
            IContainableObect c = (IContainableObject)obj;
            c.NotifyContained(self);
        }
    }
}

interface IContainableObject
{
    public void NotifyContained(Container<REPLACE_THIS>);//This line is important, see below after reading code.
}



Class ImplementingType : IContaiableObject
{
    public Container<ImplementingType> MyContainer;
    public void NotifyContained(Container<ImplmentingType> c)
    {
        MyContainer = c;
    }
}




Class Main
{
    public static void Main(args)
    {
        ImplementingType iObj = new ImplementingType();
        Container<ImplementingType> container = …
Run Code Online (Sandbox Code Playgroud)

c# generics containers interface self-reference

5
推荐指数
1
解决办法
682
查看次数

解释为局部变量会覆盖方法名称吗?

此问题一样,当在其自己的赋值中使用未定义的局部变量时,将对其进行求值nil.

x = x # => nil 
Run Code Online (Sandbox Code Playgroud)

但是当局部变量的名称与现有方法名称冲突时,它更棘手.为什么下面的最后一个例子会返回nil

{}.instance_eval{a = keys} # => []
{}.instance_eval{keys = self.keys} # => []
{}.instance_eval{keys = keys} # => nil
Run Code Online (Sandbox Code Playgroud)

ruby local-variables self-reference

5
推荐指数
1
解决办法
1108
查看次数

Symfony2 Doctrine,设置一个具有多对多自引用关系的页面

我试过按照Doctrines手册上的说明进行操作:http: //docs.doctrine-project.org/en/latest/reference/association-mapping.html#many-to-many-self-referencing

我正在尝试设置一个页面实体,它有许多子页面,我也希望能够访问页面parentPage.

按照上面的说明,symfony2告诉我,由于语义错误,我需要设置"使用".

任何人都可以告诉我该做什么让我这样做,因为我很困难.

示例代码是:

namespace Pages\Bundle\PageBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * Page
 *
 * @ORM\Table(name="Page")
 * @ORM\Entity(repositoryClass="Pages\Bundle\PageBundle\Entity\PageRepository")
 */
class Page
{
    /**
     * Constructor
     */
    public function __construct()
    {
        $this->subPages = new \Doctrine\Common\Collections\ArrayCollection();
        $this->parentPages = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * @ManyToMany(targetEntity="Page", mappedBy="subPages")
     **/
    private $parentPages;

    /**
     * @ManyToMany(targetEntity="Page", inversedBy="parentPages")
     * @JoinTable(name="sub_pages",
     *      joinColumns={@JoinColumn(name="parent_page_id", referencedColumnName="id")},
     *      inverseJoinColumns={@JoinColumn(name="sub_page_id", referencedColumnName="id")}
     *      )
     **/
    private $subPages;
Run Code Online (Sandbox Code Playgroud)

...(其他变量如下,但是内容/元数据)

运行时的错误响应是:

[Semantical Error] The annotation "@ManyToMany" in property
Pages\Bundle\PageBundle\Entity\Page::$parentPages was …
Run Code Online (Sandbox Code Playgroud)

orm doctrine many-to-many self-reference symfony

5
推荐指数
1
解决办法
5208
查看次数

实体框架代码首次自我引用带有效负载的父子

我试图在实体框架中首先使用代码进行设置并遇到困难.描述我想要完成的事情:

拥有产品实体.该产品可任选地具有一个或多个相关的"儿童"产品.产品可以是一个或多个母产品的孩子.

当我去生成一个绑定到模型类"产品"的控制器时,我收到一个错误:(更新,更具体,匹配下面的代码)

 There was an error running the selected code generator:
'Unable to retrieve metadata for 'ProductCatalog.Models.Product'.
 Multiple object sets per type are not supported. The object sets 
'Product' and 'Products' can both contain instances of type
'ProductCatalog.Models.Product'.
Run Code Online (Sandbox Code Playgroud)

这是不工作的模型类:

using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;

namespace ProductCatalog.Models
{
    // Product
    public class Product
    {
        [Key]
        public int ProductId { get; set; } // ProductID (Primary key)
        public string ProductName { get; set; } // ProductName
        public string …
Run Code Online (Sandbox Code Playgroud)

entity-framework payload self-reference ef-code-first

5
推荐指数
1
解决办法
9272
查看次数

自引用类:来自 C 接口的具体 python 类

我正在尝试设计一个可以在 Python 中轻松扩展的 C 接口(使用ctypes)。我在 C 中使用了自然习语

struct format {
    int (*can_open)(const char *filename);
    struct format * (*open)(const char *filename);
    void (*delete)(struct format *self);
    int (*read)(struct format *self, char *buf, size_t len);
};
Run Code Online (Sandbox Code Playgroud)

如果我想直接从 C 扩展这个接口,它工作得很好:

struct derived /* concrete implementation */
{
    struct format base;
};
Run Code Online (Sandbox Code Playgroud)

但我真正想做的是使用 ctypes 从 Python 实现这个接口。这是我到目前为止所拥有的:

CANOPENFUNC   = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_char_p)
#OPENFUNC     = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_char_p)
#OPENFUNC     = ctypes.CFUNCTYPE(ctypes.POINTER( python_format ), ctypes.c_char_p)
#DELETEFUNC   = ctypes.CFUNCTYPE(None, ctypes.c_void_p)
#READFUNC     = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_void_p)

def py_canopen_func( …
Run Code Online (Sandbox Code Playgroud)

c python ctypes creation self-reference

5
推荐指数
2
解决办法
887
查看次数

多对一,使用继承映射进行自引用

我有一些共同的关系和属性.所以,我想使用继承映射来简化我的模式.

我创建了一个BaseData mappedsuperclass,并让我的其他实体扩展它.此BaseData类具有每个实体所需的公共关系.

它适用于多对一关系,例如

/**
 * @ORM\MappedSuperclass
 */
class BaseData
{

    /**
    * @ORM\ManyToOne(targetEntity="Service")
    * @ORM\JoinColumn(name="service_id", referencedColumnName="id")
    */  
    protected $service;
Run Code Online (Sandbox Code Playgroud)

但是自我引用变得有点棘手.

例如,因为我想创建一个父引用,我尝试了:

/**
 * @ORM\MappedSuperclass
 */
class BaseData
{

    /**
    * @ORM\ManyToOne(targetEntity="BaseData")
    * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", nullable=true)
    */
    protected $parent;
Run Code Online (Sandbox Code Playgroud)

显然,当我尝试查询此实体时,它会导致TableNotFoundException : QLSTATE[42S02]: Base table or view not found: 1146 Table 'project.base_data' doesn't exist.

所以,我尝试了AssociationOverrides,但似乎不允许更改目标实体.

那么,有没有办法在MappedSuperclass上构建一些自引用?顺便说一句,它甚至有意义吗?

提前谢谢了 !

更新

这是anwser:

我按计划在我的BaseData mappedSuperClass中定义了protected $parentprotected $children.我用他需要的其他信息注释了它们.例如:

/**
 * @ORM\MappedSuperclass
 */
class BaseData
{

    /**
    * @Datagrid\Column(field="parent.id", title="datagrid.parent_id", visible=false, …
Run Code Online (Sandbox Code Playgroud)

orm inheritance doctrine self-reference symfony

5
推荐指数
1
解决办法
1358
查看次数

由于“直接自引用导致循环”错误,无法将 Protobuf 转换为映射

我正在尝试使用下面提到的代码将 ProtoBuf 转换为 Map。

Map map = objectMapper.convertValue(obj, Map.class);

导致此问题的示例 PB 数据:id:“1”元数据 { type:“UNIT” isValidated:false status { status:ACTIVE } }

我收到错误 java.lang.IllegalArgumentException:直接自引用导致循环(通过引用链:com.sample.samplePB["unknownFields"]->com.google.protobuf.UnknownFieldSet["defaultInstanceForType"])

protocol-buffers self-reference objectmapper

5
推荐指数
0
解决办法
627
查看次数

以节点为结构的 swift 中的 LinkedList

谁能告诉我如何快速创建一个以节点为结构、以链表为类的链表。

我试图创建一个引用自身的节点 Node 并遇到错误“值类型‘节点’不能有一个引用自身的存储属性”

为了解决这个问题,我又创建了一个 Next 类,现在我无法继续。

structure linked-list self-reference ios swift

5
推荐指数
3
解决办法
6404
查看次数